WCF WebFaultException ExceptionDetail
I'm creating a WCF service that returns data in JSON Format. I'm trying to
figure out how to best handle exceptions and I'm trying to use the
WebFaultException class to return an exception detail message in the
response, which can later be outputted to the user.
A simple Test of this method I am trying is as follows
The WCF Service method
<WebInvoke(Method:="POST",
ResponseFormat:=WebMessageFormat.Json)>
<OperationContract()>
Public Function Test() As Object
Throw New WebFaultException(Of String)("Message Details",
Net.HttpStatusCode.NotFound)
End Function
From what I found searching for answers to this questions, you should give
the service a behaviorconfiguartion which sets
includeExceptionDetailInFaults to true.
My Web.Config
<service name="WebserviceExceptionTest.Service"
behaviorConfiguration="behavior">
<endpoint address=""
behaviorConfiguration="WebserviceExceptionTest.ServiceAspNetAjaxBehavior"
binding="webHttpBinding"
contract="WebserviceExceptionTest.Service" />
</service>
<serviceBehaviors>
<behavior name="behavior">
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
Unfortunately, this appears to not do the trick for me and the response
still does not include the exception detail, the JSON string looks like
this:
{"ExceptionDetail":null,"ExceptionType":null,"Message":"Not
Found","StackTrace":null}
Does anyone have any idea of what it is I am doing wrong, or am I just
entirely on the wrong path? Thanks!
No comments:
Post a Comment