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

前端 未结 5 1714
谎友^
谎友^ 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:48

    I add the error code both as above (in the status description) and in the body of the returned page in my REST services as:

    OutgoingWebResponseContext response = WebOperationContext.Current.OutgoingResponse;
    response.StatusCode = HttpStatusCode.Unauthorized;
    response.StatusDescription = "You are not authorized.";
    HttpContext.Current.Response.Write("You are not authorized.");
    return null;
    

提交回复
热议问题