Question

I have a deserialization webmethod which returns a list of data in webservice(asmx), and I am calling the method from client-side. However, the method is giving me an array, not a list. I understand that it is because of SOAP response which returns xml format (or something like that..)
Is it possible to return a list? If then, please tell me an idea.
If not, please teach me an alternative way. (I should not use array...)

service.asmx.cs

[WebMethod]
public IList<Person> DeserializeJson(string value)
{
        JavaScriptSerializer js = new JavaScriptSerializer();
        IList<Person> tableData = js.Deserialize<IList<Person>>(value);

        return tableData;
 }

Client.aspx.cs (WebService is my service reference)

WebService.Service1SoapClient client = new WebService.Service1SoapClient();
string stream = client.CreateJsonFromDatabase();
List<WebService.Person> tableData = client.DeserializeJson(stream);
Was it helpful?

Solution

Web services do not return arrays, and they do not return lists. They return XML. The XML they return is interpreted by the client code as a list, array, or whatever.

If you consume this service by using "Add Service Reference", then you will have a choice of how to treat repeated elements in the XML. You can choose from List, Array, or several other choices.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top