简体   繁体   English

将 xml 数据发送到 web 服务而不是使用 CDATA 的最佳方法是什么?

[英]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; /// &lt;content&gt;Anything&lt;/content&gt;

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.

相关问题 解析XML标记内的CDATA的最佳方法是什么 - what is the best way to parse out CDATA inside XML tags 为 Web 服务生成动态 XML 的最佳方法是什么? - What's the Best way to Generate a Dynamic XML for Web Service? 如何使用XML Web Service发送XML数据作为请求 - How to send XML Data as Request using XML Web Service 当我拥有的所有数据都是SOAP XML格式时,使用公开暴露类型对象的Web服务的最佳方法是什么? - What's the best way to consume a web service that exposes typed objects when all data I have is in SOAP XML format? 平稳移动游戏对象而不是传送对象的最佳方法是什么? - What is the best way to move game objects, smoothly rather than teleporting it? 使用WCF服务数据结构的最佳方法是什么 - What is the best way of using WCF Service data structures 这是将数据(复杂数据/原始数据)发送到服务并获得响应(复杂数据/原始数据)的最佳方式(WCF或WEB API) - Which is the best way (WCF or WEB API) to send data(complex data/primitive data) to a service and get the response(complex data/primitive data) C#-创建将运行存储过程然后返回以json格式提取的数据的Web服务的最佳方法是什么? - C# - What is the best way to create a web service that will run a stored procedure and then return the data fetched in a json format? 将DataTables从Web服务写入XML的最佳方法? - Best way to write DataTables from a Web Service into XML? 有没有更好的方法来组织这些数据而不是使用字符串数组? - Is there a better way to organize this data rather than using string arrays?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM