I've read a few questions on SO but the solutions are all for ASP.NET webApi not dotnet core.
I've added xml support in my Startup.cs
services
.AddMvc()
.AddXmlSerializerFormatters();
Here's my controller method:
[Route("main")]
[HttpPost]
public string MainPost([FromBody]MessageModel msg)
{
_log.LogInformation("body msg ="+msg.Content);
return "test";
}
Here's my XML
<xml>
<ToUserName>toUser</ToUserName>
<FromUserName>FromUser</FromUserName>
<CreateTime>1348831860</CreateTime>
<MsgType>text</MsgType>
<Content>test content</Content>
<MsgId>1234567890123456</MsgId>
</xml>
Here's my Model class:
[XmlRoot("xml")]
public class MessageModel
{
public string ToUserName { get; set; }
public string FromUserName { get; set; }
public DateTime CreateTime { get; set; }
public string MessageType { get; set; }
public string Content { get; set; }
public int MsgId { get; set; }
}
When I send post request(with header "application/xml") to this route, it always gives me null for MessageModel msg
What am I missing here?
I know there's a DataContract thing but I can't control the xml format sending to my server so I need a way to bind xml in the format stated above to my object.
Any help or lead to any document will be much appreciated.