title: Steps to create XML using XSD and post to URL
body: <p>I was given a XSD file and sample XML file, and asked to post the XML file to a URL.</p>
  
  <p>Sample XML file</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;pingRequest&gt;
     &lt;elt&gt;&lt;/elt&gt;
     ...
  &lt;/pingRequest&gt;
  </code></pre>
  
  <p>I'm familiar with SOAP and REST, but I have never done posting pure XML file directly. Here is what I got so far.</p>
  
  <p>1) Generate C# class from XSD file </p>
  
  <pre><code> xsd.exe Test.xsd /c
  </code></pre>
  
  <p>2) Serialize from C# class to XML using XmlSerializer</p>
  
  <pre><code>public string SerializeObject(object obj, Type type)
  {
      string xml;
      var xs = new XmlSerializer(type);
      using (var ms = new MemoryStream())
      {
          xs.Serialize(ms, obj, null);
          ms.Position = 0;
          using (var sr = new StreamReader(memoryStream))
          {
              xml = sr.ReadToEnd();
          }
      }
      return xml;
  }
  </code></pre>
  
  <p>OR Should I use <a href="http://msdn.microsoft.com/en-us/library/bb387061.aspx" rel="nofollow">LINQ to XML</a> to generate XML file? </p>
  
  <p>3) Post XML to URL using WebClient</p>
  
  <pre><code>var client = new WebClient();
  var uri = new Uri("http://www.site.com/");
  string responseXML = client.UploadString(uri, requestXML);
  </code></pre>
  
  <p>Am I at the right track? If not, could you please point me to a right direction? Thanks in advance.</p>