简体   繁体   中英

How to get XML from webservice?

I am going to have XML output from web service. in fact, I write a method in web service that returns a first of objects, now I want to have this list of objects in XML format in client side.

Does web service produce XML output? If yes, how can I get XML in client side? I don't want to write XML document in web service

[WebMethod]
public string HelloWorld()
{
    return "Hello World";
}

return

<string>Hello World</string>

Please help me

I'm not entirely sure your question makes sense:

does web service produce XML output?

It can pretty much return whatever you like. You can make it return raw xml, you can make it return XmlNode -objects , or something similar.

This is what confuses me:

I don't want to write XML document in web service

Does this mean you don't want to build the XML-object at all, on the server side? If so, it will be up to your client to create the xml. How you can do that obviously depends on what data you are returning. I don't think there is any "magic" in c# that will do this for you automatically, just because it is a response from a WS.

Regarding your specific issue, you can find some guidance here .

When defining the details of your data contract and your WCF endpoint, you can decide the exact communication protocol and the form used to return your results. There, you could set the options of using REST or SOAP (see this for more) or returning results as JSON or raw data.

Hope I helped!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM