title: AspNet WebApi POST parameter is null when sending XML
body: <p>I have a web api service originally using beta bits which I've rebuilt using the release candidate bits and I'm now having this problem.</p>
  
  <p>I have a POST action that takes a complex option as the only parameter.  When I send the request with the body in json format the object is deserialised as expected, but if I send XML instead the parameter is null.</p>
  
  <p>In the beta I worked around this by disabling model binding as described in Carlos Figueira's blog post <a href="http://blogs.msdn.com/b/carlosfigueira/archive/2012/02/27/disabling-model-binding-on-asp-net-web-apis-beta.aspx">Disabling model binding on ASP.NET Web APIs Beta</a></p>
  
  <p>In the RC however they have removed the IRequestContentReadPolicy that this method was implementing.</p>
  
  <p>My action:</p>
  
  <pre><code>public List&lt;Models.Payload&gt; Post([FromBody]Models.AimiRequest requestValues)
  {
    try
    {
      if (requestValues == null)
      {
        var errorResponse = new HttpResponseMessage();
        errorResponse.StatusCode = HttpStatusCode.NotFound;
        errorResponse.Content = new StringContent("parameter 'request' is null");
        throw new HttpResponseException(errorResponse);
      }
      var metadataParams = new List&lt;KeyValuePair&lt;string, string&gt;&gt;();
      foreach (Models.MetadataQueryParameter param in requestValues.Metadata)
      {
        metadataParams.Add(new KeyValuePair&lt;string, string&gt;(param.Name, param.Value));
      }
      List&lt;Core.Data.Payload&gt; data = _payloadService.FindPayloads(metadataParams, requestValues.ContentType, requestValues.RuleTypes);
      var retVal = AutoMapper.Mapper.Map&lt;List&lt;Core.Data.Payload&gt;, List&lt;Models.Payload&gt;&gt;(data);
      return retVal; // new HttpResponseMessage&lt;List&lt;Models.Payload&gt;&gt;(retVal);
    }
    catch (System.Exception ex)
    {
      _logger.RaiseError(ex);
      throw;
    }
  }
  </code></pre>
  
  <p>My model:</p>
  
  <pre><code>public class AimiRequest
  {
    public MetadataQueryParameter[] Metadata { get; set; }
    public string ContentType { get; set; }
    public string RuleTypes { get; set; }
  }
  
  public class MetadataQueryParameter
  {
    public string Name { get; set; }
    public string Value { get; set; }
  }
  </code></pre>
  
  <p>I'm testing using Fiddler to send requests to the service.</p>
  
  <p>This works and returns me the expected results.</p>
  
  <pre><code>POST http://localhost:51657/api/search HTTP/1.1
  User-Agent: Fiddler
  Content-Type: application/json; charset=utf-8
  Accept: application/json
  Host: localhost:51657
  Content-Length: 219
  
  {
    "ContentType":null,
    "RuleTypes":null,
    "Metadata":[
      {
      "Name":"ClientName",
      "Value":"Client One"
      },
      {
      "Name":"ClientName",
      "Value":"Client Two"
      }
    ]
  }
  </code></pre>
  
  <p>This fails because the requestValues parameter is null</p>
  
  <pre><code>POST http://localhost:51657/api/search HTTP/1.1
  User-Agent: Fiddler
  Content-Type: application/xml; charset=utf-8
  Accept: application/xml
  Host: localhost:51657
  Content-Length: 213
  
  &lt;AimiRequest&gt;
    &lt;ContentType /&gt;
    &lt;RuleTypes /&gt;
    &lt;Metadata&gt;
      &lt;MetadataQueryParameter&gt;
        &lt;Name&gt;ClientName&lt;/Name&gt;
        &lt;Value&gt;Client One&lt;/Value&gt;
      &lt;/MetadataQueryParameter&gt;
      &lt;MetadataQueryParameter&gt;
        &lt;Name&gt;ClientName&lt;/Name&gt;
        &lt;Value&gt;Client Two&lt;/Value&gt;
      &lt;/MetadataQueryParameter&gt;
    &lt;/Metadata&gt;
  &lt;/AimiRequest&gt;
  </code></pre>