I have one webservice:
public class Product
{
public int ProductId { get; set; }
public string ProductName { get; set; }
}
public class Service : System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public List<Product> GetItems()
{
List<Product> productList = new List<Product>()
{
new Product{ProductId=1,ProductNam开发者_开发技巧e="Pencil"},
new Product{ProductId=2,ProductName="Pen"}
};
return productList;
}
and in a asp.net application I am consuming it like:
localhost.Service s = new localhost.Service();
List<localhost.Product> k = new List<localhost.Product>();
k = s.GetItems().ToList(); // i am getting the values here.
now my question is do I need to serialize my webmethod as i am returning custom types? when should we serialize ? is it necessary at all, if yes , then what are the conditions?
No, you don't have to do it. Executing engine will notice that you return custom type and serialize it into SOAP ( != XML ) properly.
PS: Consider moving to WCF
精彩评论