简体   繁体   中英

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.

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).

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.

I was wondering if there is a better way to do this rather than using CDATA?. The CDATA files are very small (less than 20KB).

JD

I'd suggest Base64-Encoding the XML fragment.

There is no need to use CDATA. You can pass the xml fragment directly as is.

See, for example, http://msdn.microsoft.com/en-us/library/aa480498.aspx

UPDATE:

Steve pointed out that you have a string parameter not XmlElement parameter. 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

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? Make the single parameter part of the url or querystring.

This is the more "RESTful" way of doing things.

It's just a standard file upload.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM