Issue with sending XML to Web Api via http Post request
<p>I would like to send the following XML document to my Web Api 2 controller; however, the <code>[FromBody]</code> parameter is always null.</p>

<p>Here is the request XML body:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;razorInbound server="PortfolioExposureServer" request="lookupRiskPointRecord"&gt;
  &lt;caller&gt;RazorClient&lt;/caller&gt;
  &lt;responseMode&gt;xml&lt;/responseMode&gt;
  &lt;body&gt;
    &lt;conditions&gt;
      &lt;fromOffset&gt;0&lt;/fromOffset&gt;
      &lt;top&gt;100&lt;/top&gt;
      &lt;condition&gt;
        &lt;keyPath&gt;
          &lt;keyElement nodeOffset='1'&gt;Currency&lt;/keyElement&gt;
          &lt;keyElement nodeOffset='2'&gt;ID&lt;/keyElement&gt;
        &lt;/keyPath&gt;
        &lt;lookupValue&gt;USD&lt;/lookupValue&gt;
      &lt;/condition&gt;
    &lt;/conditions&gt;
  &lt;/body&gt;
&lt;/razorInbound&gt;</code></pre>
</div>
</div>
</p>

<p>Using Postman to send the request, is as follows :</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>POST /api/razorXmlRequest HTTP/1.1
Host: localhost:5000
Content-Type: application/xml
Cache-Control: no-cache
Postman-Token: 6ca91ebf-31e0-77f2-6f81-cb9993b69b1a

&lt;razorInbound server="PortfolioExposureServer" request="lookupRiskPointRecord"&gt;
  &lt;caller&gt;RazorClient&lt;/caller&gt;
  &lt;responseMode&gt;xml&lt;/responseMode&gt;
  &lt;body&gt;
    &lt;conditions&gt;
      &lt;fromOffset&gt;0&lt;/fromOffset&gt;
      &lt;top&gt;100&lt;/top&gt;
      &lt;condition&gt;
        &lt;keyPath&gt;
          &lt;keyElement nodeOffset='1'&gt;Currency&lt;/keyElement&gt;
          &lt;keyElement nodeOffset='2'&gt;ID&lt;/keyElement&gt;
        &lt;/keyPath&gt;
        &lt;lookupValue&gt;USD&lt;/lookupValue&gt;
      &lt;/condition&gt;
    &lt;/conditions&gt;
  &lt;/body&gt;
&lt;/razorInbound&gt;</code></pre>
</div>
</div>
</p>

<p>And the Web Api 2 controller :</p>

<p>NOTE: The <code>param</code> parameter is always <code>null</code></p>

<p>I believe I need a proper class definition to correctly map the XML request, but I'm not sure how to construct it.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>using System;
using System.Threading.Tasks;
using System.IO;
using System.Text;
using RazorServices;
using System.Net.Http;
using System.Web.Http;
using System.Xml.Linq;
using System.Net;
using System.Xml;

namespace RazorWebApi.Controllers
{
    [Route("api/razorXmlRequest")]
    public class RazorXmlRequestController : ApiController
    {
        public class RawXml {
            public string RazorXml { get; set; }
        }

        [HttpPost]
        public async Task&lt;HttpResponseMessage&gt; Post([FromBody]RawXml param )
        {
            HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.OK);

            // code omitted...
   
            return resp;
        }
    }
}</code></pre>
</div>
</div>
</p>

<p>And by the way, we are currently getting around this issue by setting up a <code>StreamReader</code> object to pull from <code>this.Request.Content</code>; however in my unit test I need to send my xml as a parameter.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>[HttpPost]
        public async Task&lt;HttpResponseMessage&gt; Post()   // [FromBody]RawXml param )
        {
            HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.OK);

            StreamReader sr = new StreamReader(await this.Request.Content.ReadAsStreamAsync(), Encoding.UTF8);
            string xml = sr.ReadToEnd();

            if (xml == null || xml.Length &lt; 4)
            {
                throw new RazorServicesException("Invalid XML");
            }
            RazorSession cred = RzWebApi.Cred;
            string reply = await RzWebApi.RazorSrv.xmlRequests.Request(cred, xml);
            resp.Content = new StringContent(reply, System.Text.Encoding.UTF8, "text/plain");
            return resp;
        }</code></pre>
</div>
</div>
</p>