IDIspatchMessageInspector

IDIspatchMessageInspector

我实现了idispatchMessageInspector.afterReceiverequest
然后我这样配置:

<configuration>
  <system.serviceModel>
    <services>
      <service
        name="Microsoft.WCF.Documentation.SampleService"
        behaviorConfiguration="inspectorBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/SampleService" />
          </baseAddresses>
        </host>
        <endpoint
          address=""
          binding="wsHttpBinding"
          contract="Microsoft.WCF.Documentation.ISampleService"
        />

      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="inspectorBehavior">
          <serviceInspectors />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <extensions>
      <behaviorExtensions>
        <add
          name="serviceInspectors"
          type="Microsoft.WCF.Documentation.InspectorInserter, HostApplication, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
        />
      </behaviorExtensions>
    </extensions>
  </system.serviceModel>
</configuration>

但没用。
我签入程序集和本地引用,但未找到Microsoft.WCF.Documentation.InspectorInserterHostApplicationdll
我在网上搜索下载HostApplicationdll,但什么也没找到。
我该怎么办?
我需要实现更多的东西,或者我只需要这个配置。

最佳答案

我发现使用同样扩展了属性的iservicebehavior实现附加idispatchMessageInspector实现要容易得多。然后在applyDispatchBehavior方法中,将消息检查器附加到所有通道中的所有端点。
这对我帮助很大。
示例代码:

public class MyServiceBehavior : Attribute, IServiceBehavior
{
    public void ApplyDispatchBehavior( ServiceDescription serviceDescription,
        ServiceHostBase serviceHostBase )
    {
        foreach( ChannelDispatcher cDispatcher in serviceHostBase.ChannelDispatchers )
            foreach( EndpointDispatcher eDispatcher in cDispatcher.Endpoints )
                eDispatcher.DispatchRuntime.MessageInspectors.Add( new RequestAuthChecker() );
    }
}

然后在执行服务合同时,您可以将属性添加到类中。
[ServiceBehavior( InstanceContextMode = InstanceContextMode.PerCall )]
[MyServiceBehavior]
public class ContractImplementation : IServiceContract
{

07-27 15:12