I would like to send the following XML document to my Web Api 2 controller; however, the [FromBody]
parameter is always null.
Here is the request XML bo
Final solution was to change the Post param type to XElement
:
[Route("api/razorXmlRequest")]
public class RazorXmlRequestController : ApiController
{
/// <summary>
/// Raw Razor request XML
/// </summary>
/// <returns>Razor reply message as text</returns>
[HttpPost]
public async Task<HttpResponseMessage> Post([FromBody]XElement xml)
{
HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.OK);
RazorSession cred = RzWebApi.Cred;
string reply = await RzWebApi.RazorSrv.xmlRequests.Request(cred, xml);
resp.Content = new StringContent(reply, System.Text.Encoding.UTF8, "application/xml");
return resp;
}
}
This worked straight-away without even providing the XmlFormatter
as the gentlemen had suggested above (@TusharJ, thank you anyway for your input).
You can configure Web API to use XmlSerializer
in your WebApiConfig.Register
as follows;
config.Formatters.XmlFormatter.UseXmlSerializer = true;