Am currently trying to use the Web API and accept a HTTP POST containing an XML. I was under the impression that this could be automatically deserialized into an object, but I am missing something.

public class Item
    public int Value { get; set; }

This one works, I receive the XML from SoapUI and can act upon it

public HttpResponseMessage Post(int id, HttpRequestMessage request)
    var doc = new XmlDocument();

    HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, new Item() { Value = id });
    return response;

I'd like to have this though:

public HttpResponseMessage Post(int id, [FromBody]List<Item> items)
    return Request.CreateResponse(HttpStatusCode.OK);

Trying to post this:


What did I miss?

2 Years
Discussion Span
Last Post by pritaeas

Why is it always you find the answer right after posting. I forgot to add:

var xml = GlobalConfiguration.Configuration.Formatters.XmlFormatter;
xml.UseXmlSerializer = true;

as mentioned on SO.

The XML I am sending looks like this now:


Can't remember where I read that it had to be specified as ArrayOfXxx

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.