[英]What is the best way to send xml data to a web service rather than using CDATA?
I have a web service that takes a single string parameter.我有一个 web 服务,它采用单个字符串参数。
In my case I need to send a string which is an xml document where one of its elements contains an xml fragment (which I will use to create a file).在我的情况下,我需要发送一个字符串,它是一个 xml 文档,其中一个元素包含一个 xml 片段(我将使用它来创建一个文件)。
So for example I am sending:例如,我发送:
<people>
<person>
<name>J Smith</name>
<value><![CDATA[<content>rest of xml document here</content>]]></value>
</person>
</people>
I used.. to create an xml file.我用.. 创建了一个 xml 文件。
I was wondering if there is a better way to do this rather than using CDATA?.我想知道是否有比使用 CDATA 更好的方法来做到这一点? The CDATA files are very small (less than 20KB).
CDATA 文件非常小(小于 20KB)。
JD京东
I'd suggest Base64-Encoding the XML fragment.我建议对 XML 片段进行 Base64 编码。
There is no need to use CDATA.无需使用 CDATA。 You can pass the xml fragment directly as is.
您可以按原样直接传递 xml 片段。
See, for example, http://msdn.microsoft.com/en-us/library/aa480498.aspx例如,参见http://msdn.microsoft.com/en-us/library/aa480498.aspx
UPDATE:更新:
Steve pointed out that you have a string parameter not XmlElement parameter.史蒂夫指出你有一个字符串参数而不是 XmlElement 参数。 I'm not sure if it would still work that way (though I feel like it could:).
我不确定它是否仍然可以这样工作(尽管我觉得它可以:)。
Another option besides CDATA and Base64 would be Xml encoding, eg除了 CDATA 和 Base64 之外的另一个选择是 Xml 编码,例如
var xml = new XmlDocument();
var node = xml.CreateElement("root");
node.InnerText = "<content>Anything</content>";
var xmlString = node.InnerXml; /// <content>Anything</content>
How about a standard HTTP POST using Mutipart/Form-Data?使用 Mutipart/Form-Data 的标准 HTTP POST 怎么样? Make the single parameter part of the url or querystring.
使 url 或查询字符串的单个参数部分。
This is the more "RESTful" way of doing things.这是更“RESTful”的做事方式。
It's just a standard file upload.这只是一个标准的文件上传。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.