views:

433

answers:

4

I am calling a webservice in C# and am getting an array of objects back.

Is there a way of getting an xml string instead?

A: 

You can make a raw call directly by using WebClient and get your webservice return value as SOAP-formatted XML data.

Rubens Farias
A: 

If you are using the ScriptService attribute on your web service class (server side), that forces the service to return JSON. If you have it, delete it. (Same for ScriptMethod attribute on methods.)

Cylon Cat
+1  A: 

Change the return type of the webservice method into a string, and serialize your data into XML before returning it.

Also, why do you want to do this? If you're getting an array of objects back, isn't that what the XML/SOAP contains?

David Lively
A: 

Do you want the entire XML, including all of the SOAP chatter, or just an XML representation of the array itself?

If you only want the array as XML, then serialize it using the XmlSerializer class. You can either serialize it within the WebService and return it as a string, or leave it as an array and serialize it on the client side.

Aaronaught