0

我有一个SoapExtension,目前只写一个日志:

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");
        }

    }
}

我尝试用两个web.config文件注册它

<webServices>
  <soapExtensionTypes>
    <add type="WebAdminServices.SoapExtensions.CatchInputParametersExtension,WebAdminServices" priority="1" group="Low"/>
  </soapExtensionTypes>
</webServices>

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; }
    }

}

这是由注册的

    [WebMethod(Description = "Test1")]
    [CatchInputParametersAttribute(Priority=1)]
    public string Test1(int a, int b, int c)
    {
        // do stuff

        return stuff;
    }

但它们似乎都不起作用,日志文件从不显示这些++++++行。请问有什么提示吗?

4

1 回答 1

0

好吧,这有点傻。SoapExtension工作正常,但我通过自动生成的调用 web 方法,HTTP Post认为在SoapExtension下面执行。但事实并非如此。

因此,要触发其执行,您需要SOAP直接使用请求通过客户端调用它。为此,我使用了WebServiceStudio,它分析给定.wsdl并允许您发出SOAP请求。

更多信息:在 ASP.NET 中使用 SOAP 扩展

于 2014-01-30T09:43:33.557 回答