Last post Apr 22, 2009 06:45 PM by Amit Sharma
Apr 21, 2009 02:42 PM|garyaid|LINK
1 - How would I go about validating the xml in the body of a POST prior to it being serialized into my object?
I have a problem with user(s) sending incorrect elements, ... and i would like to give them a more succinct error message other than "... server puked ..." :-)
2 - How would I sort the xml elements in the body of a POST prior to it being serialized into my object? I am looking for a "default" (read - least painful) way to handle user(s) who can't get there elements into alphabetic order for serialization. Yes,
I know I could order them using attributes, but the same problem exists...user(s) who can't get the xml elements in the body of a POST into the proper order...
REST WCF XmlSerialization
Apr 22, 2009 05:11 PM|Amit Sharma|LINK
1) Perform Message Validation with Schema Validation in WCF -->
http://msdn.microsoft.com/en-us/library/cc949095.aspx (you will have to apply it to webHttpBinding instead of wsHttpBinding)
2) Can you please let me know why do you want to sort the elements? If you really want to then you should be able to find help with reading XML using linq
Apr 22, 2009 06:04 PM|garyaid|LINK
Thank you for your time on this. on item 1), I am using the WCF REST Preview 2, so I really have no web.config save for <system.serviceMode><serviceHostingEnvironment aspNetCompatibilityEnabled="true" />... and that's about it. The MSDN reference you pointed
out seems to be a completely different solution. Do I need to change my WCF REST configuration and setup the endpoints...etc. to accomplish this?
And, item 2), If a client sends their payload (POST body xml) in the wrong order, it does not get serialized properly, and in some cases, causes this small portion of a response:
><P class="heading1"><B>Error Status Code:</B> 'InternalServerError'</P><P><B>Details: </B>Object reference not set to an instance of an object.</P>
Which happens when the xml elements in the POST body are not in the proper order, which is alphabetic since i do not specify an order, and a validation process can not complete because data was not loaded... which would cause and error too.
So, if I could just automatically sort the xml elements on the inbound side, WHILE IN TEST MODE, i could probably prevent a number of errors up front. I would also insert a warning msg in the response to the client (i have that capability) that the list
was out of order, and that "..." is the correct order. Gives them a chance, and speeds up testing.
Once the client went to production, they would have to get it right, or have their order rejected.
Yes, I could use LinqToXml, but where would i intercept this prior to it being de-serialized?
Apr 22, 2009 06:45 PM|Amit Sharma|LINK
you can intercept the message at the message inspector level and do the checking. The msdn post shows how to do that.