如何在Web API应用程序中读取XML文件? [英] How can I read an XML file in a Web API app?

查看:177
本文介绍了如何在Web API应用程序中读取XML文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有任何不同,则表明XML文件是从手持设备发送的.

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

对于类似问题 ,但是我不确定更流行的答案是否真的能解决我的情况(客户端似乎正在传递自定义类型(ComputerInfo)),而在我的情况下,这是一个实际的XML文件,是否传递了arg

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

?

令我怀疑的是,XMLDocument类型无法识别,并且没有"Resolve"上下文菜单项可以将其正式引入项目中.)

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

而且,CF应用程序还能处理返回的Task吗?我对此表示怀疑,因此:接收XML文件的Web API方法应该是什么样的?

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?

推荐答案

请尝试尝试此

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.

这篇关于如何在Web API应用程序中读取XML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆