开发者

IDIspatchMessageInspector

开发者 https://www.devze.com 2023-01-12 12:48 出处:网络
I Implement IDispatchMessageInspector.AfterReciveRequest Then I configure like this: <configuration>

I Implement IDispatchMessageInspector.AfterReciveRequest Then I configure like this:

<configuration>
  <system.serviceModel>
    <services>
      <service 
        name="Microsoft.WCF.Documentation.SampleService"
        behaviorConfiguration="inspectorBehavior">
    开发者_JS百科    <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.


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

精彩评论

暂无评论...
验证码 换一张
取 消