Thursday, 18 September 2014

Posting XML to a WebAPI method always null



I am performing a systems integration. The client documentation states


"messages are transmitted with the HTTP CONTENT_TYPE header set to “application/x-www-form-urlencoded”.



<Message>
<Originator>ACME Solutions</Originator>
<Payload>
...message xml content goes here...
</Payload>
</Message>


I am using WebApi 2 and the default controller action for post has the definition of



public void Post([FromBody]string value)


Everytime I post this message to my web service the value received is always null


I have tried creating a class with the same definition but that always has the properties as null.



public void Post([FromBody]Message value)


If I change the definition to a more generic one I can extract the Xml Document from the request content but thats not the way I want to go as it makes unit testing difficult.



public void Post(HttpRequestMessage request)


Can anyone suggest where I am going wrong and why the xml message isn't mapping to my class.


No comments:

Post a Comment