title: Manual SOAP Serialization in Windows Store Apps
body: <p>This is a continuation of my previous question regarding the Expect100Continue Header not being able to be removed in Windows Store apps, for reference: <a href="https://stackoverflow.com/questions/12799196/servicepoint-expect100continue-for-windows-store-apps">ServicePoint.Expect100Continue for Windows Store Apps</a></p>
  
  <p>I stepped back now and am now using the HttpClient to manually POST HttpContent to the Webservice. I am using classes like this:</p>
  
  <pre><code>[XmlRoot(ElementName = "myRootElement", Namespace = "myNamespace.com")]
  public class MyRootElement
  {
       [XmlElement(Namespace = "myNamespace.com", ElementName = "myParameter")]
       public string MyParameter { get; set; } 
  }
  </code></pre>
  
  <p>To serialize and construct the body of the HttpContent, i am using serialization code like this:</p>
  
  <pre><code>using (MemoryStream stream = new MemoryStream())
  {
         XmlWriterSettings settings = new XmlWriterSettings();
         settings.OmitXmlDeclaration = true;
         settings.Encoding = Encoding.UTF8;
         settings.Indent = false;
         settings.NamespaceHandling = NamespaceHandling.Default;
  
         XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
         ns.Add("", "myNamespace.com");
  
         using (XmlWriter xmlWriter = XmlWriter.Create(stream, settings))
         {
             XmlSerializer ser = new XmlSerializer(input.GetType());
             ser.Serialize(xmlWriter, input, ns);
         }
  
         var arr = stream.ToArray();
         body = Encoding.UTF8.GetString(arr, 0, arr.Length);
     }
  
     var result = "&lt;s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"&gt;&lt;s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"&gt;" +
              body
              + "&lt;/s:Body&gt;&lt;/s:Envelope&gt;";
  </code></pre>
  
  <p>However the output is flawed. The namespace is only written at the root element but not on the parameter element. There is a "?" character at the beginning of body i am unable to remove or find the source of. </p>
  
  <p>Also i'd like to know if there is a better way then string concatonation to enclose the body in a SOAP envelope.</p>