Validating XML requests in a C# RESTful MVC web service
I have a C# MVC web service that receives XML. Additionally I have XSD against which the request XML can be validated against.
Now, I've implemented an XmlValueProviderFactory to be able to send XML to the action method. (Thanks to http://www.nogginbox.co.uk/blog/xml-to-asp.net-mvc-action-method for this)
However I'm struggling to implement a decent way of verifying the XML against the XSD before it is picked apart by the XmlValueProviderFactory ready for the action method. Essentially I want to validate the XML before passing it to the action method.
Can anyone provide any suggestions to do this? Currently I'm validating the XSD within the XmlValueProviderFactory, placing the validation results in a ViewBag and then using that ViewBag data 开发者_如何学JAVAin the action method logic to decide whether to return an failure message to the client. This doesn't seem right.
Perhaps validating against the XSD at this point is incorrect. Perhaps this solution is ok (it works, but using ViewBag seems clunky).
Any opinions appreciated.
精彩评论