ASPA MVC4 WebApi parameter is null - on only one machine

I have an MVC4 WebApi project that works fine on my development machine but acts weirdly on a deployed server. Both Blocks - Server 2008 with IIS 7.5

I have one controller with a single Post method that takes a complex type as a parameter. I force the use of the XmlMediaType and XmlSerialization formatter, so HttpConfiguration.Formatters.XmlFormatter.UseXmlSerializer = true , and the complex type is the "old school" XmlSerializable .

For the same request, my dev box correctly deserializes the XML in the body into an instance of a complex type and the result returned to the client from the Post method is correct. On another machine, an instance of the null parameter on arrival in the Post method.

I have to repeat that this is an identical code and an identical request (except for the host name). It makes me think that there must be something ecologically between the machines. Unfortunately, after many searches, I still do not know what it can be.

I should also point out that if I change my Post method to accept a string parameter and then internal deserialization on both boxes is the same and correct.

I also implemented my own serializer ( XmlFormatter.SetSerializer ) and dev box works again; another creates a null parameter. Interestingly, when I register the request body before deserializing in this case, I see the same XML on both machines. It's just that one cell discards the deserialized value somewhere along the way to the Post method.

Can anyone suggest some suggestions on how to proceed to eliminate this strange behavior?

+4
source share
1 answer

Check ModelState on the controller. If for some reason deserialization fails, it is logged as a ModelState exception. It can help you at least figure out what is going on.

+2
source

Source: https://habr.com/ru/post/1444912/


All Articles