0

I have working WCF service where I need to add some functionality regarding authorization. I have have created class which inherits from ServiceAuthorizationManager and successfully added it in app.config. It's working properly.

I also need to implement class which implements IDispatchMessageInspector, so I could do some message validation.

I have followed many examples like this, this, this, this, this and some others. Also questions in SO like this.

They all seem to have same configuration in app.config file. However, when I try that and run code, it seems that class implementing IDispatchMessageInspector is never being called when I debug. I've added break points, but they are never being hit.

Am I missing something obvious?

<extensions>
  <behaviorExtensions>
    <add name="MessageInspectorBehaviourExtension" type="MultipleEndpoints.MessageInspectorBehaviourExtension, RL_Managed_Service" />
  </behaviorExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
    <behavior name="RLServiceBehavior">
      <serviceDebug includeExceptionDetailInFaults="False"/>
      <serviceAuthorization serviceAuthorizationManagerType="MyProject.Services.AuthorizationService,MyProject"/>
      <MessageInspectorBehaviourExtension />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="RLServiceBehavior" name="MultipleEndpoints.RL_Managed_Service">
    <endpoint address="" binding="basicHttpBinding" contract="MultipleEndpoints.container_db_ops" bindingConfiguration="TransportSecurity"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    <host>
      <baseAddresses>
        <!--  --><add baseAddress="http://localhost:49224/My_Service/"/>
      </baseAddresses>
    </host>
  </service>
</services>
Community
  • 1
  • 1
Mantas Čekanauskas
  • 2,218
  • 6
  • 23
  • 43

2 Answers2

2

After you fixed the config I think I know the reason. You try to register your behavior extension as service behavior, while IDispatchMessageInspector should be registered at endpoint level (like in the link you mentioned - see the last example there). Here is config file that should work for you:

<extensions>
  <behaviorExtensions>
    <add name="MessageInspectorBehaviourExtension" type="MultipleEndpoints.MessageInspectorBehaviourExtension, RL_Managed_Service" />
  </behaviorExtensions>
</extensions>
<behaviors>
  <serviceBehaviors>
    <behavior name="RLServiceBehavior">
      <serviceDebug includeExceptionDetailInFaults="False"/>
      <serviceAuthorization serviceAuthorizationManagerType="MyProject.Services.AuthorizationService,MyProject"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="RLEndpointBehavior">
      <MessageInspectorBehaviourExtension />
    </behavior>
  </endpointBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="RLServiceBehavior" name="MultipleEndpoints.RL_Managed_Service">
    <endpoint address="" binding="basicHttpBinding" behaviorConfiguration="RLEndpointBehavior" contract="MultipleEndpoints.container_db_ops" bindingConfiguration="TransportSecurity"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    <host>
      <baseAddresses>
        <!--  --><add baseAddress="http://localhost:49224/My_Service/"/>
      </baseAddresses>
    </host>
  </service>
</services>
Igor Labutin
  • 1,406
  • 10
  • 10
0

I found another way I could register IDispatchMessageInspector without app.config. In `OnStart' method you can simply loop through endpoints.

service = New ServiceHost(GetType(My_Service))

For Each endpoint In service.Description.Endpoints
    If Not endpoint.Contract.Name.Equals("IMetadataExchange") Then
        endpoint.EndpointBehaviors.Add(New MessageInspectorBehaviour)
    End If
Next
Mantas Čekanauskas
  • 2,218
  • 6
  • 23
  • 43