The Way to Programming
The Way to Programming
Are you checking for Model binding errors? stick this at the beginning of your controller methods:
if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); }
Deserialise the stream yourself
In your controller, can you get the raw content of the request and try to deserialise it yourself? This will also help. (this is just for troubleshooting and should not be how you deal with the deserialisation)
try { string data = Request.Content.ReadAsStringAsync() ; new XmlSerializer(typeof(yourType)).Deserialize(new StringReader(data)); } catch(Exception ex) { Debug.WriteLine(ex.Tostring); }
it was an issue in Model binding and expecting XML namespace information. Yes I am able to fix the issue,but it’s using DataContractSeralizer instead XmlSerializer.
I have already configured GlobalConfiguration.Configuration.Formatters.XmlFormatter.UseXmlSerializer = true; in Startup.cs.
If this is set GlobalConfiguration . Configuration . Formatters.XmlFormatter.UseXmlSerializer = true, then I’m afraid i cannot think of any other reasons why there should still be problems. Is there a specific error message? I cannot think of anything else though…
It was a problem with model mapping. on API side few request type properties are XML attributes and when it’s mapped with other class type using automapper, it looks unable to map it correctly. Now i have made all request type properties as XML elements and mapped it, now no media type error and works fine.
Sign in to your account