Elmah + SOAP

95 views
Skip to first unread message

jrummell

unread,
Apr 16, 2008, 2:24:48 PM4/16/08
to ELMAH
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!

Atif Aziz

unread,
Apr 17, 2008, 2:45:22 PM4/17/08
to el...@googlegroups.com
> If anyone has found a better way to capture SOAP exceptions with Elmah

Seems like the right way to do it if one had to, but I wonder why one would need error logging (tracing being different) in the first place. An error occuring during a SOAP transaction does not constitue as an unhandled error. It's simply being propagated to the client where it needs to be handled. It could lead to some false-negatives to log such errors because it's possible that the client is inducing errors by making invalid calls. On the other hand, I can imagine that this could help to spot issues where the exception is being caused by a bug in the server code. Either way, it gets very hard in a service scenario to distinguish one case from the other so tracing would be more appropriate than using ELMAH.

Reply all
Reply to author
Forward
0 new messages