WebFaultException http status code is not passed
- by Mike Bantegui
I have the following service method:
<OperationContract()>
<WebGet([ResponseFormat]:=WebMessageFormat.Json)>
Function ShouldThrowException() As Boolean
It's implementation does only one thing, which is to throw a WebFaultException.
Public Function ShouldThrowException() As Boolean Implements IRestService.ShouldThrowException
Throw New WebFaultException(Of String)("This should fail", HttpStatusCode.BadRequest)
End Function
My web.config reads as:
<endpointBehaviors>
<behavior name="WebEndpointBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
.. snip ..
<webHttpBinding>
<binding name="WebBinding"
crossDomainScriptAccessEnabled="true">
<security mode="None" />
</binding>
</webHttpBinding>
.. snip ..
<service name="RestService">
<endpoint address=""
binding="webHttpBinding"
behaviorConfiguration="WebEndpointBehavior"
bindingConfiguration="WebBinding"
contract="IRestService"
name="RestService">
</endpoint>
</service>
When I call ShouldThrowException via my browser, I only get the following:
"This should fail"
I was expecting to get a 400 Bad Request error on the page. If I inspect the page using FireBug, I see that the HTTP status code that was returned is a 200 OK. According to this blog post, I should be seeing this exception. Except I'm not. What am I doing wrong here?