Attributes and Web Services

  • Thread starter Thread starter stotty
  • Start date Start date
S

stotty

Send a data structure using Web Services.
Data structure looks like:

Class Person {
int age;
string name;
Pets pet;
}

However the age field is optional and the name field is required and
must be between 4 and 20 characters.

The web service just returns the class i.e
[WebMethod]
public Person PersonInfo(Person person)
{
return person;
}
 
You can't put attributes on the class which will validate this for you.
You are going to have to code something yourself which will validate the
contents that are sent into the web service (by checking the values
yourself).

Also, the age field will always have a value in it, because integers in
..NET are not nullable (at least until .NET 2.0 where you can use
Nullable<T>), so you need something else to indicate that the value was not
set (or you could use a negative integer, because someone can never be a
negative age).

Hope this helps.
 
I don't want to put the attributes on the whole class but rather each
individual element. Something like this:
[Serializable]
Class Person {
int age;
[Lenght(4,20)]
string name;
[Length(4,4)]
string ID;

Pets pet;

}
 
Back
Top