These days I am working on a Project in which I need to implement a Service Oriented Architecture. The services are exposed as Web Services. I was planning to return the List<User> to the client but found out that List cannot be returned since its not serializable. I plan to use ArrayList and that worked. If you would like to return an ArrayList from the WebService you can do so check out the simple code below:
[WebMethod]
[System.Xml.Serialization.XmlInclude(typeof(User))]
public ArrayList GetAllUsers()
{
User user = new User();
return user.GetAllUsers();
}
Above is your WebMethod and below is the defination of the class User:
[Serializable]
public class User
{
/* PRIVATE FIELDS */
private int _userID;
private string _firstName;
private string _lastName;
/* PUBLIC PROPERTIES */
public int UserID
{
get { return _userID; }
set { _userID = value; }
}
Pretty Simple Right!