从使用 WCF WebHttp API 实现的服务中的 POST 方法获取原始 xml [英] Get raw xml from POST method in service implemented using WCF WebHttp API

查看:27
本文介绍了从使用 WCF WebHttp API 实现的服务中的 POST 方法获取原始 xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 RESTful 方法构建网络服务,并且正在使用 WCF WebHttp API (.NET v4).为了满足某些遗留功能,我需要通过 POST 接受原始 XML 消息并对其进行处理.例如,我的一种方法如下所示:

I am building a webservice using RESTful approach and am using WCF WebHttp API (.NET v4). To satisfy some legacy functionality I need to accept raw XML message via POST and process it..For example one of my methods looks like:

[WebInvoke(UriTemplate = "Hello", Method = "POST")]
public Message ProcessMessage(string xmlMessage)
{
    if (String.IsNullOrWhiteSpace(xmlMessage))
    {
        return WebOperationContext.Current.CreateXmlResponse(ProcessingFailedReply);
    }
    var message = XElement.Parse(xmlMessage);
    return WebOperationContext.Current.CreateXmlResponse(ProcessingSuccessfullReply);
}

但是,每次我尝试将一些 xml 发布到/Hello"时,我都会收到一条消息,指出格式无效并且它需要专门编码的字符串.我猜这个 API 正在使用标准模式来自动序列化 xmlMessage.当我访问帮助 ("/help") 时,我得到了我的 xmlMessage 的示例格式:

However, every time I try to POST some xml to "/Hello" I get a message that the format is invalid and it wants specifically encoded string. I guess the API is using standard schema to automatically serialize xmlMessage. When I visit the help ("/help") I am given an example format for my xmlMessage:

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">String content</string>

在这种情况下,我如何允许和处理原始请求?我查看了 API,唯一相关的类 (WebOperationContext.Current.IncommingRequest) 没有任何方法来检索原始消息...

How do I allow and process the POSTed request as raw in this scenario? I looked over the API and the only relevant class (WebOperationContext.Current.IncommingRequest) does not have any methods to retrieve raw message...

谢谢Z...

推荐答案

创建一个 XElement 类型的输入参数,您可以以任何方式查询 XML.

Create an input parameter of type XElement and you can query the XML any way you want.

这篇关于从使用 WCF WebHttp API 实现的服务中的 POST 方法获取原始 xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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