IBlog<Johan>

This and that in a developer's life in general

News

Follow johandanforth on Twitter

Random Links

Walkthroughs and Tutorials

[SoapExtension] I did it again :(

This is the second time I try to test a SoapExtension class by calling a web service method from a browser! *hit self*

I've written the tiniest SoapExtension that captures web service exceptions, then publish it through my modified variant of Microsoft's Exception Management Application Block. Without comments and stuff it looks like this:

       public class SoapExceptionHandler : SoapExtension

       {

 

              public override object GetInitializer( LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)

              {

                     //not used

                     return null;

              }

 

              public override object GetInitializer(Type WebServiceType)

              {

                     //not used

                     return null;

              }

 

              public override void Initialize(object initializer)

              {

                     //not used

              }

 

              public override void ProcessMessage(SoapMessage message)

              {

                     switch(message.Stage)

                     {

                           case SoapMessageStage.AfterSerialize:

                                  if(message.Exception != null)

                                         ExceptionManager.Publish(message.Exception.InnerException);

                                  break;

                     }

              }

       }

 

That's all you need. Register the SoapExtension to "listen" to the entire virtual root like this:

...  
<system.web>

  <webServices>

    <soapExtensionTypes>

      <add type="ExceptionManagement.SoapExceptionHandler,ExceptionManagement" priority="1" group="0" />

    soapExtensionTypes>

  webServices>
...

 

UPDATE: Got rid of some source, just to shorten the post somewhat.

Comments

Ashutosh Shankar (aashank@msn.com) said:

Great stuff!!
Thanks for posting it. I was looking for something like this - a generic exception handler for web services. This does provide a great lead.

Thanks.
# May 4, 2004 2:47 PM