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

前端 未结 5 1720
谎友^
谎友^ 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条回答
  •  旧时难觅i
    2020-12-04 18:41

    With .net 4, throw a WebFaultException(T errorDetail, HttpResponseCodecode)

    Here you set your response type to another object type, which makes sense, and also you set the ResponseCode that you want.

    The errorDetail must be serializable

    http://blogs.msdn.com/b/endpoint/archive/2010/01/21/error-handling-in-wcf-webhttp-services-with-webfaultexception.aspx

提交回复
热议问题