What is the best way to return errors from a WCF service in a RESTful way?

前端 未结 5 1719
谎友^
谎友^ 2020-12-04 18:11

Using WCF in a RESTful way seems great. I’m a big fan of the big guns like simplicity and flexibility, but I also love the way the Urls end up looking. What can I say, I’m a

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 18:38

    See this thread for a similar question.

    In a nutshell I believe you can set the HTTP status code (to one of the error codes), and provide your custom message in the StatusDescription property:

    OutgoingWebResponseContext response = WebOperationContext.Current.OutgoingResponse;
    response.StatusCode = System.Net.HttpStatusCode.Forbidden;
    response.StatusDescription = "Custom";
    

    I don't know much about the prevalence of this technique in the real world unfortunately.

提交回复
热议问题