IDIspatch消息检查器

发布于 2024-09-15 15:29:46 字数 1544 浏览 4 评论 0原文

我实现 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 但我什么也没找到。

我必须做什么?

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

I Implement IDispatchMessageInspector.AfterReciveRequest
Then I configure like this:

<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>

but it doesn't work .

I check in my assembly and in my local reference and I didnt found Microsoft.WCF.Documentation.InspectorInserter or HostApplication dll
I search in the net to download HostApplication dll but I found nothing.

What do I have to do?

I need to implement more thing or I Just need this configuration.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

带刺的爱情 2024-09-22 15:29:46

我发现使用也扩展了 Attribute 的 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
{

I found it much easier to attach my IDispatchMessageInspector implementation using an IServiceBehavior implementation that also extends Attribute. Then in the ApplyDispatchBehavior method, attach your message inspector to all the all of the endpoints in all of the channels.

This article helped me greatly.

Example code:

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() );
    }
}

Then in the implementation of your service contract, you can just add the attribute to the class.

[ServiceBehavior( InstanceContextMode = InstanceContextMode.PerCall )]
[MyServiceBehavior]
public class ContractImplementation : IServiceContract
{
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文