A web app I’m working on which uses web service calls a lot is using Elmah for error logging.
Unfortunately web service calls consistently result in the useless ‘Server was unable to process request.’ message.
Originally I thought I could patch Elmah to log session variables then log the detail in the session in a Global.asax application_error handler. Unfortunately, the Elmah error handler appears to consistently run before the application_error handler, so that doesn’t work (although it’s still nice to have session variables logged).
So I did some quick hacking on Elmah to get it to pull out the useful SoapException.Detail message.
In Elmah’s Error.cs file, after:
if (httpException != null)
{
_statusCode = httpException.GetHttpCode();
_webHostHtmlMessage = Mask.NullString(httpException.GetHtmlErrorMessage());
}
I added:
// If this is a SOAP exception, then replace the message information with more useful info
System.Web.Services.Protocols.SoapException soapException = baseException as System.Web.Services.Protocols.SoapException;
if (soapException != null && soapException.Detail != null)
{
_detail = baseException.Message
+ System.Environment.NewLine + System.Environment.NewLine
+ "Soap Detail: " + Mask.NullString(soapException.Detail.InnerText)
+ System.Environment.NewLine + System.Environment.NewLine
+ "Regular detail: " + System.Environment.NewLine + _detail;
_message = Mask.NullString(soapException.Detail.InnerText);
// not sure how big these detail strings get, so arbitrarily cap the size on the short message
if (_message.Length > 100)
{
_message = _message.Substring(0, 100);
}
}
And now I get Elmah error logs like:
Instead of:
And detail messages like:
Instead of: