WCF 4.0 REST服务应用程序中的RequestInterceptor

WCF 4.0 REST服务应用程序中的RequestInterceptor,wcf,c#-4.0,Wcf,C# 4.0,我有一个WCF 4.0 REST服务应用程序,我想截获传入的请求并检查自定义头。在我的解决方案中,我使用以下默认端点 <standardEndpoints> <webHttpEndpoint> <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" /> </webHttpEndpoint> </standard

我有一个WCF 4.0 REST服务应用程序,我想截获传入的请求并检查自定义头。在我的解决方案中,我使用以下默认端点

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

我已尝试创建IDispatchMessageInspector和相应的behaviorExtension元素,并将适当的behaviorExtension和endPointBehavior添加到我的web.config中。我还需要做什么才能让拦截弹开火


我认为我对WCF真正工作原理的完全缺乏了解正在扼杀我。我的IParameterInspector很容易实现,而且工作得很好。我希望这会很容易实现。

后续:


由于我的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>

要启动拦截器,在使用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;
      }
   }

您是否有用于身份验证的示例拦截器?