xml - Web Api Post value is always null when using Chrome Postman Plugin -
i'm following example here http://www.asp.net/web-api/overview/creating-web-apis/creating-a-web-api-that-supports-crud-operations i'm having trouble getting receive post request chrome postman plugin.
here's example of xml i'm posting. have set content-type header in postman application/xml.
<?xml version="1.0" encoding="iso-8859-1"?> <product> <category>groceries</category> <name>new post</name> <price>1.39</price> </product>
i have tried following solution model null on xml post doesn't seem make difference. here's webapiconfig file.
public static void register(httpconfiguration config) { config.formatters.add(new xmlmediatypeformatter()); config.formatters.xmlformatter.usexmlserializer = true; config.routes.maphttproute( name: "defaultapi", routetemplate: "api/{controller}/{id}", defaults: new { id = routeparameter.optional } ); }
i'm hitting right end point , can see when debug item null.
public httpresponsemessage postproduct(product item) { item = repository.add(item); var response = request.createresponse(httpstatuscode.created, item); string uri = url.link("defaultapi", new { id = item.id }); response.headers.location = new uri(uri); return response; }
any ideas?
edit: seems work ok when post same values json. need able test xml though.
apply datacontract
so, dto class.
[datacontract(namespace="")] public class product { public int id { get; set; } public string name { get; set; } public string category { get; set; } public decimal price { get; set; } }
alternatively, send right namespace info.
Comments
Post a Comment