public class SoapExceptionHandler : System.Web.Services.Protocols.SoapExtension
{
public override void ProcessMessage(System.Web.Services.Protocols.SoapMessage message)
{
if (message.Stage == SoapMessageStage.AfterSerialize)
{
if (message.Exception != null)
{
Logger.Write(message.Exception.InnerException);
}
}
}
public override object GetInitializer(Type serviceType)
{
return null;
}
public override object GetInitializer(LogicalMethodInfo methodInfo,
SoapExtensionAttribute attribute)
{
return null;
}
public override void Initialize(object initializer){ }
}
[AttributeUsage(AttributeTargets.Method)]
public class ExceptionHandlingAttribute : SoapExtensionAttribute
{
public override Type ExtensionType{get { return typeof(SoapExceptionHandler); }}
public override int Priority{get{return 0;}set{}}
}
You can apply this attribute to your XML Web service methods and thus enable your newly created SoapExtension.
[WebMethod] [ExceptionHandling] public void Foo(){}