2010-07-14 55 views
0

我有一個WCF 4.0 REST服務我想攔截傳入請求並檢查自定義標頭的應用程序。在我的解決方案,我用下面的默認端點WCF 4.0中的RequestInterceptor REST服務應用程序

<standardEndpoints> 
<webHttpEndpoint> 
     <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" /> 
</webHttpEndpoint> 
</standardEndpoints> 

我試圖創建一個IDispatchMessageInspector和相應BehaviorExtensionElement並加入適當的behaviorExtension和endPointBehavior到我的web.config。我還需要做些什麼才能使攔截器着火?

我假設我完全缺乏WCF的實際工作知識在這裏殺死我。我的IParameterInspector很容易實現並且完美地工作。我希望這會很容易實現。

回答

0

追問:


由於我的RequestInterceptor的目標都集中在認證,我能夠利用ServiceAuthorizationManager派生的類來實現我想要的結果,並添加到web.config中,如下所示。

<behaviors> 
    <serviceBehaviors> 
    <behavior> 
     <!-- This behavior enables Auth Token Verification --> 
     <serviceAuthorization serviceAuthorizationManagerType="Something.Service.Authorization, Something.Service" /> 
     <serviceMetadata httpGetEnabled="true" /> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
+0

你有沒有你的自定義請求攔截後有一個示例攔截器,您用於身份驗證? – BenAlabaster 2015-10-14 11:22:14

0

爲了使攔截器火,你也需要實現自定義的主機廠家再攔截器添加到您的服務如下,你實現使用Microsoft.ServiceModel.Web.RequestInterceptor

public class MyCustomHostFactory : ServiceHostFactory 
    { 
     protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) 
     { 
     var serviceHost = new WebServiceHost2(serviceType, true, baseAddresses); 
     RequestInterceptor interceptor = MySolution.RequestInterceptorFactory.Create(); 
     serviceHost.Interceptors.Add(interceptor); 
     return serviceHost; 
     } 
    } 
相關問題