Why do we need serialization in web service
Posted
by Cloud2010
on Stack Overflow
See other posts from Stack Overflow
or by Cloud2010
Published on 2010-06-17T16:28:27Z
Indexed on
2010/06/17
16:33 UTC
Read the original article
Hit count: 176
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,ProductName="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?
© Stack Overflow or respective owner