I have a SoapExtension
which, for now, only writes a log:
public class CatchInputParametersExtension : SoapExtension
{
public override object GetInitializer(Type serviceType)
{
return null;
}
public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
{
return null;
}
public override void Initialize(object initializer)
{
//nothing to do
}
public override void ProcessMessage(SoapMessage message)
{
Logger.Log("++++++++ Before Everything +++++++ " + message.ToString(), LogLevel.Info);
switch (message.Stage)
{
case SoapMessageStage.BeforeSerialize:
Logger.Log("++++++++ Before Serialize +++++++ " + message.ToString(), LogLevel.Info);
break;
case SoapMessageStage.AfterSerialize:
Logger.Log("++++++++ After Serialize +++++++ " + message.ToString(), LogLevel.Info);
break;
case SoapMessageStage.BeforeDeserialize:
Logger.Log("++++++++ Before Deserialize +++++++ " + message.ToString(), LogLevel.Info);
break;
case SoapMessageStage.AfterDeserialize:
Logger.Log("++++++++ After Deserialize +++++++ " + message.ToString(), LogLevel.Info);
break;
default:
throw new Exception("invalid stage");
}
}
}
I tried registering it with both web.config
file
<webServices>
<soapExtensionTypes>
<add type="WebAdminServices.SoapExtensions.CatchInputParametersExtension,WebAdminServices" priority="1" group="Low"/>
</soapExtensionTypes>
</webServices>
and SoapExtensionAttribute
[AttributeUsage(AttributeTargets.Method)]
public class CatchInputParametersAttribute : SoapExtensionAttribute
{
private int priority;
public override Type ExtensionType
{
get { return typeof(CatchInputParametersExtension); }
}
public override int Priority
{
get { return priority; }
set { priority = value; }
}
}
which is registered by
[WebMethod(Description = "Test1")]
[CatchInputParametersAttribute(Priority=1)]
public string Test1(int a, int b, int c)
{
// do stuff
return stuff;
}
but none of them seems to work, the log file never shows those ++++++
lines. Any hints, please?
Ok, this is a little bit silly. The SoapExtension
is working fine, but I was calling the web method through the automatically generated HTTP Post
, thinking that the SoapExtension
was executing underneath. But it wasn't.
So for trigger its execution you need to call it through a client using a SOAP
request directly. For that purpose I used WebServiceStudio, which analyzes a given .wsdl
and lets you make SOAP
requests.
More info: Using SOAP Extensions in ASP.NET.