2010-07-14 56 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; 
     } 
    } 
相关问题