验证 C# RESTful MVC Web 服务中的 XML 请求
我有一个接收 XML 的 C# MVC Web 服务。此外,我还有 XSD,可以根据它来验证请求 XML。
现在,我已经实现了一个 XmlValueProviderFactory,以便能够将 XML 发送到操作方法。 (感谢 http://www.nogginbox。 co.uk/blog/xml-to-asp.net-mvc-action-method)
但是,我正在努力实现一种体面的方法,在 XML 被 XSD 拆开之前对其进行验证。 XmlValueProviderFactory 准备就绪为动作方法。本质上,我想在将 XML 传递给操作方法之前对其进行验证。
谁能提供任何建议来做到这一点?目前,我正在 XmlValueProviderFactory 中验证 XSD,将验证结果放入 ViewBag 中,然后在操作方法逻辑中使用该 ViewBag 数据来决定是否向客户端返回失败消息。这似乎不对。
也许此时针对 XSD 进行验证是不正确的。也许这个解决方案还可以(它有效,但使用 ViewBag 似乎很笨拙)。
任何意见表示赞赏。
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 in 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论