[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.

No Comments