问题
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