Do it the right way 

With all the talk going on I agree that this is bad:

public class MyWebService
   public string GetSomeXML()
     // get some xml
     return xml;



public class MyClient
   public static void Main()
      MyWebService objWS = new MyWebService();
      string strXML = objWS.GetSomeXML();
      XmlDocument doc = new XmlDocument();
      // processing

A lot better (in most situations) is:

public class MyWebService
   public XmlDocument GetSomeXML()
     // return xml

The former scenario serializes the document directly into the output SOAP stream, therefore bypassing double string (de)serialization.

There are special cases, when one would like to bypass the other approach (passing XML as XmlDocument) on the server side. If you have all the data ready and want to pass it as quickly as humanly possible, without rehydrating the entire full blown DOM-capable object, you would use System.String (xsd:string in the XML world) and System.Text.StringBuilder to contacenate it.

If you don't know what to choose I propose this:

  • It is year 2004, therefore platform and tool support is available in a way that XML processing is not a limitation from the XSD type system -> platform type system conversion side. Therefore choose XmlDocument.
  • Choose XmlDocument.
  • Choose the string way if and only if you are expecting clients which have no other way to bridge/decouple the raw SOAP XML string into something programmatic inside your platform.

In any case, things will change in late July or early August.

Categories:  XML
Monday, May 17, 2004 6:17:32 PM (Central Europe Standard Time, UTC+01:00)  #    Comments


Monday, May 31, 2004 5:38:31 PM (Central Europe Standard Time, UTC+01:00)
Here's a better approach, and you don't have to choose DOM vs (XmlReader | XPathNavigator): (How to return well-formed XML from WebServices without the DOM: from XmlReader and XPathNavigator)
All comments require the approval of the site owner before being displayed.
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview
Copyright © 2003-2024 , Matevž Gačnik
Recent Posts
RSS: Atom:

The opinions expressed herein are my own personal opinions and do not represent my company's view in any way.

My views often change.

This blog is just a collection of bytes.

Copyright © 2003-2024
Matevž Gačnik

Send mail to the author(s) E-mail