【问题标题】:IDIspatchMessageInspectorIDISpatchMessageInspector
【发布时间】:2013-03-15 04:56:15
【问题描述】:

我实现了 IDispatchMessageInspector.AfterReciveRequest 然后我这样配置:

<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.InspectorInserterHostApplication dll 我在网上搜索下载HostApplication dll,但没有找到。

我该怎么办?

我需要实现更多的东西,或者我只需要这个配置。

【问题讨论】:

  • 您的配置不完整。发布完整的配置、检查器代码和行为代码。同时删除那两个空帖子。

标签: c# wcf idispatchmessageinspector


【解决方案1】:

我发现使用同样扩展 Attribute 的 IServiceBehavior 实现附加 IDispatchMessageInspector 实现要容易得多。然后在 ApplyDispatchBehavior 方法中,将消息检查器附加到所有通道中的所有端点。

这个article对我帮助很大。

示例代码:

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
{

【讨论】:

  • 是的,很不幸,有些文档有多糟糕。
  • 我认为 wcf.stackexchange.com 有一个很好的商业案例
  • 晚了,但是我现在可以给你一个大大的打击!说真的,这几天我一直在努力解决这个问题,你的帖子解决了我所有的问题!哇!谢谢!
  • @Andomar Programming WCF Services by Juval Lowy 就像是 WCF 的圣经
  • 这太棒了!但是,如果我只想将我的 Inspector 应用于某些服务方法,我该怎么做呢?
猜你喜欢
  • 1970-01-01
  • 2010-12-12
  • 1970-01-01
  • 2011-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多