XML : MVC 6 XML API post won't bind to model

My eventual goal is to receive Twilio XML Posts when a new SMS is received, but for now I'm stuck on binding XML data to a model.

ASP.NET 5, MVC 6

I've enabled the XML formatters with: services.AddMvc().AddXmlDataContractSerializerFormatters().AddXmlSerializerFormatters();

I have a simple model class:

  public class XmlTest  {      public string PropertyOne { get; set; }      public string PropertyTwo { get; set; }  }    

And a simple API method:

  [HttpPost]  public IActionResult Post(XmlTest xmlTest)  {      //Application Logic  }    

Using PostMan, I am posting this XML data:

  <?xml version="1.0" encoding="UTF-8"?>  <XmlTest>     <PropertyOne>ValueOne</PropertyOne>     <PropertyTwo>ghi789</PropertyTwo>  </XmlTest>    

When the data is posted, xmlTest is initialized but the values of PropertyOne and PropertyTwo are not set. If I add the [FromBody] attribute to XmlTest, then the value of xmlTest is null when the post occurs.

Can anyone help with what I'm doing wrong here?

JSON works just fine, but Twilio will only post xml.

Thanks!

No comments:

Post a Comment