从使用 WCF WebHttp API 实现的服务中的 POST 方法获取原始 xml

编程入门 行业动态 更新时间:2024-10-19 20:33:40
本文介绍了从使用 WCF WebHttp API 实现的服务中的 POST 方法获取原始 xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在使用 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/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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 19:28:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141119.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:原始   方法   WebHttp   WCF   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!