WebFaultException http status code is not passed

Posted by Mike Bantegui on Stack Overflow See other posts from Stack Overflow or by Mike Bantegui
Published on 2012-07-03T15:12:39Z Indexed on 2012/07/03 15:15 UTC
Read the original article Hit count: 446

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about wcf