Passing Validation exceptions via WCF REST

前端 未结 2 522
闹比i
闹比i 2021-02-11 03:31

I am using WCF and REST, and I have complex types, which are working fine. Now I need to check for validation, I am thinking of using DataAnnotations e.g.

publi         


        
2条回答
  •  别跟我提以往
    2021-02-11 04:06

    I would look into writing a custom IDispatchMessageInspector implementation where, in the AfterReceiveRequest method, you manually invoke the validation architecture.

    I won't go into the details of how to call the Data Annotations validation architecture as I'm sure you can find that somewhere online if you don't already know how to do it. That said, once you have your validation results you can enumerate them and then, if there are any failed validations, you can throw a generic validation fault filled with the details from the AfterReceiveRequest implementation.

提交回复
热议问题