Custom JSON IErrorHandler in WCF returning StatusCode 200/504 when should return 400

1.3k Views Asked by At

I have a WCF service that among other bindings also uses WebHttpBinding for JSON inputs/results.

I made a custom IErrorHandler implementation in order to be able to set the StatusCode to 400 when something goes wrong and also return a JSON understandable message. It´s the straight implementation that you can find everywhere (nice way described here).

My problem is: when I test it locally using Visual Studio Web Development Server (Cassini) it works perfectly. However, when I deploy it to my test server (Windows 2008 with standard config for IIS and everything else) it does not work.

When I call it and debug with Firebug I get a HttpStatusCode 200 as a return and no response text. With Fiddler I get a HttpStatusCode 504 and no return at all. However, the behavior I expected (and what happens locally) is a call to the error callback of the ajax call with the responseText set.

I debugged it remotely and everything looks just fine. The execution pipeline is OK and all the classes are called as they should be just like they are locally, except it does not work.

Any suggestions? I´m pretty much out of options here to figure this out.

Thanks a lot!

2

There are 2 best solutions below

1
On

if firebug and fiddler are giving different results, what happens if you telnet to it directly and perform a request (Something like:)

    GET /VirtualDirectoryAndGetData HTTP/1.1
    HOST: example.com
    [carriage return]

It wouldn't surprise me if you're somehow getting odd headers/formatting back (to explain why firebug/fiddler disagree)

Another thing to test would be publishing to your dev machine to see if it's a machine-specific issue or a server vs dev webserver issue.

If it's happening anywhere outside VS, you might also try commenting out the lines where you set

  rmp.StatusCode = System.Net.HttpStatusCode.BadRequest;
  rmp.StatusDescription = "Bad request";

This may indicate whether it's a response code issue or an error handler issue.

If you can edit your question to include the results (with sensitive info removed), we'll see if we can track it down further.

Edit: after looking at the question again, it may well be that the server is erroring before it can send ANY response. FF might assume 200 by default, whereas ie might assume 504 (Gateway Timeout). This is total speculation but is possible. Do you see anything in the event logs?

0
On

I had a similar issue which I was able to solve. Take a look at the IIS settings. Details on how I overcame the issue are in this post: IErrorHandler returning wrong message body when HTTP status code is 401 Unauthorized