title: Reading XML content from Body of WebAPI call is cut off at beginning
body: <p>I'm creating a sort of proxy service that needs to process calls containing XML from the body of a <code>POST</code> to my WebAPI service and then <code>POST</code> it on to another service.</p>
  
  <p>The odd thing is when I receive the XML message from the <code>POST</code> the 1st part of the XML from the body is cut off. Initially I thought maybe buffer size, or message was too big so I cut out a lot of the XML test message being sent reducing what was being sent. However the XML is <em>still</em> cut off in the same place.</p>
  
  <p>I've tried the following (2) methods to read the XML <strong>BODY</strong> in the WebAPI service and the result is the same:</p>
  
  <pre><code>var reader = new StreamReader(Request.Content.ReadAsStreamAsync().Result);
  string originalMessage = reader.ReadToEnd();
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>        var result = "";
          Request.Content.ReadAsStreamAsync().ContinueWith(x =&gt;
          {
  
              using (var sr = new StreamReader(x.Result))
              {
                  result = sr.ReadToEnd();
              }
          });
  </code></pre>
  
  <p>Here is a snippet the original XML:</p>
  
  <pre><code>&lt;Message version="123" release="001" xmlns="http://www.mysite.com/schema"&gt;
    &lt;Header&gt;
      &lt;To Att1="A"&gt;001&lt;/To&gt;
      &lt;From Att2="B"&gt;002&lt;/From&gt;
      &lt;ID&gt;9876&lt;/ID&gt;
  </code></pre>
  
  <p>Here is the <em>beginning</em> of the content after reading it in the WebAPI controller <code>POST</code>:</p>
  
  <pre><code>&lt;/To&gt;
      &lt;From Att2="B"&gt;002&lt;/From&gt;
      &lt;ID&gt;9876&lt;/ID&gt;
  </code></pre>
  
  <p>See how it starts at the 'closing' tag of the <code>&lt;To&gt;</code> element? That's obviously not the beginning of the XML that it was sent.</p>
  
  <p>The even more peculiar thing is the 'Content Size' when inspected before it is sent and after is 4188 on both sides. Something else interesting is that I have an old fashion <code>.asmx</code> tester (as opposed to a Web API service) that does the identical thing. When I read the incoming XML message in that app using the following:</p>
  
  <pre><code>    // Get raw request body
      Stream receiveStream = HttpContext.Current.Request.InputStream;
  
      // Move to beginning of input stream and read
      receiveStream.Position = 0;
      using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
      {
      // Load into XML document
      xmlSoapRequest.Load(readStream);
      }
  </code></pre>
  
  <p>...I see the <em>full</em> XML message. So not sure why the <code>.asmx</code> can read it but not the WebAPI service fully.</p>
  
  <p>What am I doing wrong in my WebAPI <code>POST</code> call to where I can't see the full XML message that was sent in the body of the request?</p>