I recently put together a WebService project and added the appropriate
Elmah settings in the web.config. I quickly learned that Elmah does
not see SoapExceptions since they don't bubble up to the http module.
I found the following resources on SOAP error handling and the new
signaling features of Elmah and came up with a solution.
http://www.codeproject.com/KB/aspnet/ASPNETExceptionHandling.aspx
(SOAP error handling)
http://dotnetslackers.com/articles/aspnet/ErrorLoggingModulesAndHandlers.aspx
(Elmah 1.0b2)
I implemented a SoapExtension that catches any SoapExceptions and
hands them off to Elmah. Here is the class:
public class ElmahSoapExtension : SoapExtension
{
public override object GetInitializer(LogicalMethodInfo
methodInfo, SoapExtensionAttribute attribute)
{
return null;
}
public override object GetInitializer(Type serviceType)
{
return null;
}
public override void Initialize(object initializer)
{
}
public override void ProcessMessage(SoapMessage message)
{
if (message.Stage == SoapMessageStage.AfterSerialize &&
message.Exception != null)
{
// signal the exception for Elmah to see
ErrorSignal.FromCurrentContext().Raise(message.Exception);
}
}
}
I also had to this to my web.config in the system.web section:
<webServices>
<soapExtensionTypes>
<add type="Web.Services.ElmahSoapExtension,
Web.Services" />
</soapExtensionTypes>
</webServices>
If anyone has found a better way to capture SOAP exceptions with Elmah
please let me know.
Thanks!