本文介绍了WCF RESTFul 服务 - 将 XML 作为字符串传递给服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要能够将 XML 作为字符串传递给 RESTFul WCF 服务,但是我很难做到这一点.有人可以让我知道我怎么做吗?它必须作为字符串发送,我不能将其包装在数据合同等中.下面的服务合同示例
I need to be able to pass XML to a RESTFul WCF service as a string, however I am struggling to do so. Can someone please let me know how I could do this? It must be sent as a string, I cannot wrap it in a data contract etc. Example of the service contract below
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "lookup",
BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Xml)]
Stream LookupPostcode(string requestXml);
非常感谢
推荐答案
这是一个重大的问题,但您可以像这样将 XML 包装在 标签中.
It's a major hack, but you can wrap your XML inside a <string>
tag like this.
XmlDocument body = new XmlDocument();
body.Load(...);
postData = @"<string xmlns='http://schemas.microsoft.com/2003/10/Serialization/'><![CDATA[" + body.OuterXml + "]]></string>";
这篇关于WCF RESTFul 服务 - 将 XML 作为字符串传递给服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!