How can I read an XML file in a Web API app?

吃可爱长大的小学妹 提交于 2019-12-24 09:57:37

问题


If this makes any difference, the XML file is being sent from a handheld device.

There are a couple of interesting answers to a similar question here, but I'm not sure the more popular answer really addresses my situation (where the client seems to be passing a custom type (ComputerInfo)) whereas in my case it is an actual XML file is the arg being passed.

The second answer looks perhaps more "up my alley/what the doctor ordered" but I don't know what signature my method should have. Something like this:

public async Task<HttpResponseMessage> PostXMLFile(XMLDocument xmlFile) {

?

Adding to my doubts is that the XMLDocument type is unrecognized, and there is no "Resolve" context menu item to formally introduce it to the project).

And, can a CF app deal with a returned Task anyway? I doubt it, so: what should my Web API method receiving an XML file look like?


回答1:


Try this instead,

public async Task<HttpResponseMessage> PostXMLFile(XElement xElement) {

Whether you user the above signature or,

public HttpResponseMessage PostXMLFile(XElement xElement) {

the client will see exactly the same response. Use the first signature when you need to make an async request within your action method.



来源:https://stackoverflow.com/questions/21994108/how-can-i-read-an-xml-file-in-a-web-api-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!