12

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.

arcain
  • 14,920
  • 6
  • 55
  • 75
tzlil
  • 121
  • 1
  • 3
  • Your configuration is not complete. Post complete configuration, inspector code and behavior code. Also delete those two empty posts. – Ladislav Mrnka Aug 19 '10 at 21:08

1 Answers1

22

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
{
MonkeyWrench
  • 1,809
  • 2
  • 24
  • 48
  • Yup, its very unfortunate how bad some of the documentation is. – MonkeyWrench Feb 14 '13 at 16:35
  • 1
    I think there's a good business case for wcf.stackexchange.com – arcain Mar 14 '13 at 20:54
  • Late however I can give you a big smacker right now! Seriously, banging my head against this for days now and your post solved all my problems! MWAH! Thank you! – Dr Schizo Jul 26 '13 at 13:45
  • @Andomar Programming WCF Services by Juval Lowy is like bible for WCF – avi Jul 27 '13 at 00:41
  • This is awesome! However, if I wanted to apply my Inspector to only some of the Service Methods, how would I go about that? – Shevek Dec 03 '14 at 11:16
  • Don't add it to all of the Service Methods? Put an if statement in the foreach loop to skip the ones you want to skip? – MonkeyWrench Feb 02 '15 at 21:42
  • All these upvotes and still not marked as the answer... such it life... – MonkeyWrench May 17 '17 at 21:18
  • And the link is dead, f*ck. In the first code, did you mean ContractImplementation instead of new RequestAuthChecker() ? – Jay Croghan Jan 12 '18 at 07:51
  • Sorry for the dead link. You'd think MSFT would keep their links alive.. Anyways, no. RequestAuthChecker was my own implementation of the interface used there. – MonkeyWrench Feb 22 '18 at 16:39