Summary
Exception serialization behaviour for [WebMethod] differs between ‘all on same server’ use and ‘real world use’.
Situation
I have a webservice implemented, in foo.aspx, like this :
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json, XmlSerializeString = false)]
public static Fruit InsertUpdateFruitWebService()
{
return FruitHelper.InsertUpdateFruit();
}
The webservice is called from within bar.aspx using jQuery – $.ajax.
If some sort of problem occurs in InsertUpdateFruit an exception is thrown, the ‘error’ callback specified within $.ajax is invoked and a JSON blob is passed as an argument to the ‘error’ callback function.
The Good News
When the browser and the server are on the same machine this all works fine.
The Not So Good News
When the browser and the server are not the same machine all you get in the JSON blob passed as an argument to the ‘error’ callback is this :
{"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}
No stacktrace, no exception details, etc.
The Question
Can anyone point me in the direction of what might cause this ?
OK an answer to this is to make amendments to the Web.config file (or whichever .config file you would like use) so that the customErrors attribute is set to ‘Off’ like so …
There are plenty of circumstances where this might not be a great solution but it works for me on this project.
Credit needs to go Dave Ward and his blog posting at http://encosia.com/use-jquery-to-catch-and-display-aspnet-ajax-service-errors/ (it’s actually in the comments) which reminded me of this .