2014-01-29 44 views
0

我有一個SoapExtension其中,現在,只寫日誌:的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; 
    } 

但它們都不起作用,日誌文件從不顯示那些++++++行。請提供任何提示?

回答

0

好吧,這有點傻。 SoapExtension工作正常,但我通過自動生成的HTTP Post調用web方法,認爲SoapExtension正在下面執行。但事實並非如此。

因此,爲了觸發其執行,您需要直接通過客戶端使用SOAP請求來調用它。爲此,我使用了WebServiceStudio,它分析給定的.wsdl並讓您發出SOAP請求。

更多信息:Using SOAP Extensions in ASP.NET