title: Web API POSTing XML object is always null
body: <p>I've seen a few similar questions to this but none of the solutions have helped me.</p>
  
  <p>This code works perfectly when I'm passing a JSON payload. But with an XML load, the passed object to the controllers POST method is always NULL.</p>
  
  <p>My console app simply makes a POST http request to my ASP MVC Controller and at this point the passed XML payload object is always null.</p>
  
  <p>This is my console application showing the http request object being set and the XML Xdocument payload being constructed:</p>
  
  <pre><code>    XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
      XElement clientRequestElement = new XElement(xmlns + "PLTSActivation",
              new XAttribute(XNamespace.Xmlns + "xsi", xsi),
              new XElement(xmlns + "iSIClientID", iid.ToString()),
              new XElement(xmlns + "organizationId", ooid),
              new XElement(xmlns + "statusDescription", "Success"));
  
      doc.Add(clientRequestElement);
  
      return doc.ToString(SaveOptions.DisableFormatting);
  }
  
  
  public static void PostXML()
  {
      string _URL = "http://localhost:24689/api/PTShandler/postxml";
  
      string _OOID = "TEST";
      string convertedJSONPayload = "";
  
      var payloadObj = new
      {
          XmlPayload = ConstructProvisioningRequest(99783971, _OOID)
      };
  
      try
      {
          var httpWebRequest = (HttpWebRequest)WebRequest.Create(_URL);
                  httpWebRequest.Headers.Add("ORGOID", _OOID);
                  httpWebRequest.Headers.Add("Culture", "en-US");
                  httpWebRequest.ContentType = "application/xml";
                  httpWebRequest.Accept = "application/xml";
                  httpWebRequest.Method = "POST";
  
  
          using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
          {
              streamWriter.Write(payloadObj.ToString());
              streamWriter.Flush();
              streamWriter.Close();
          }
      }
  </code></pre>
  
  <p>This is my PTShandler controller showing the POST method:</p>
  
  <pre><code>[System.Web.Mvc.HttpPost]
  public string PostXML(object xmlPayload)
  {
  
      //*****The 'xmlPayLoad' object is always null*****
      List&lt;SplitXML&gt; returnedPopulatedXMLObject = SetXMLstrings(XDocument.Parse(xmlPayload.ToString()));
  
      foreach (var XMLitem in returnedPopulatedXMLObject)
      {
          _ClientID = XMLitem.ISIClientID;
  
          _OrganizationID = XMLitem.OrganizationID;
  
          _Status = XMLitem.Status;
      }
  
      string stringXDoc;
  
      return stringXDoc = "POSTed";
  }
  </code></pre>
  
  <p>This is my Global.asax.cs file:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Http;
  using System.Web.Mvc;
  using System.Web.Optimization;
  using System.Web.Routing;
  
  namespace RESTful.CallBackService
  {
  public class WebApiApplication : System.Web.HttpApplication
  {
          protected void Application_Start()
          {
              var xml = GlobalConfiguration.Configuration.Formatters.XmlFormatter;
              xml.UseXmlSerializer = true;
  
              AreaRegistration.RegisterAllAreas();
  
              WebApiConfig.Register(GlobalConfiguration.Configuration);
              FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
              RouteConfig.RegisterRoutes(RouteTable.Routes);
              BundleConfig.RegisterBundles(BundleTable.Bundles);  
          }
  }
  }
  </code></pre>
  
  <p>And this is my App_Start WebApiConfig.cs file:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web.Http;
  using System.Xml.Serialization;
  
  namespace RESTful.CallBackService
  {
  public static class WebApiConfig
  {
          public static void Register(HttpConfiguration config)
          {
              config.Routes.MapHttpRoute(
              name: "DefaultApi",
              routeTemplate: "api/{controller}/{action}/{id}",
              defaults: new
              {
                  id = RouteParameter.Optional
              }
          );
          }
  }
  }
  </code></pre>
  
  <p>Can anyone see where Im going wrong?</p>