开发者

XML response of webservice call in C#

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

Is there a way of getting an 开发者_Go百科xml string instead?


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?


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


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.)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜