IDIspatchMessageInspector

前端 未结 1 1982
被撕碎了的回忆
被撕碎了的回忆 2021-02-13 20:21

I Implement IDispatchMessageInspector.AfterReciveRequest Then I configure like this:


  

        
相关标签:
1条回答
  • 2021-02-13 20:51

    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 讨论(0)
提交回复
热议问题