In order to use content negotiation you need to accept a class which the model binder can bind to in your controller. Like this:
public class Document
{
public int Id { get; set; }
public string BaseUrl { get; set; }
public string Name { get; set; }
public int Active { get; set; }
public Page[] Pages { get; set; }
}
public class Page
{
public int Id { get; set; }
public string Url { get; set; }
public string InternalId { get; set; }
public string Name { get; set; }
public bool Active { get; set; }
}
Then you accept this as your argument instead of a XmlDocument:
[RoutePrefix("Document")]
public class DocumentController : ApiController
{
[HttpPost]
[Route("AddDocument")]
public IHttpActionResult AddDocument([FromBody] Document doc)
{
// Do Stuff
return Ok();
}
}
And now you can change the Content-Type header in your request to be either application/xml, text/xml or application/json depending on the format being posted.