title: Passing an Xml from a Web Service
body: <p>I have a web service which returns something of type <code>MyData</code>.</p>
  
  <pre><code> public class MyData
   {
          public string Name;
          [XmlElement("item")]
          public Object[] DataItems;
   }
  </code></pre>
  
  <p>I have used <code>Object[]</code> for <code>DataItems</code> because the type of array could be of several types. I have two different classes which I could successfully send using this method. See below.</p>
  
  <p><code>clientResults</code> is the filled DataSet.</p>
  
  <pre><code>MyData returnResult = new MyData();
  
  MyFirstClass[] resultData = new MyFirstClass[clientResults.Tables[0].Rows.Count];
  
  resultData.MyFirstClassProperty1 = "Blah Blah";
  resultData.MyFirstClassProperty2 = "Blah Blah";
  
  returnResult.DataItems = resultData.
  </code></pre>
  
  <p>I could easily change <code>MyFirstClass</code> to <code>MySecondClass</code> and set its own properties and the web service would properly serialize both the classes and every one was happy!</p>
  
  <p>However now there is a need where I have to pass an XML returned by the <code>DataSet.GetXml()</code> function.</p>
  
  <p>Naturally, what I did was </p>
  
  <pre><code> XmlDocument xdoc = new XmlDocument();
   xdoc.LoadXml(clientResults.GetXml());
   resultData.DataItems = new XmlDocument[] { xdoc };
  </code></pre>
  
  <p>But this is throwing an exception</p>
  
  <pre><code>System.InvalidOperationException: There was an error generating the XML document. ---&gt; System.InvalidOperationException: The type System.Xml.XmlDocument may not be used in this context.
  </code></pre>
  
  <p>So what I thought, ok lets try it with XmlNode.</p>
  
  <pre><code>XmlDocument xdoc = new XmlDocument();
  xdoc.LoadXml(clientResults.GetXml());
  XmlNode xElement = xdoc.SelectSingleNode("/");
  result.DataItems = new XmlNode[] { xElement };
  </code></pre>
  
  <p>Still its throwing the SAME exception. What could be wrong?</p>
  
  <p>How do I properly pass an XML through a web service?</p>