4

I am trying to extend my service endpoint behaviour with custom MessageInspector, extension works fine and its picked up, but only if I don’t define the “name” parameter on behaviour tag and don’t define specific behaviorConfiguration on the endpoint. This means I am extending all endpoints and this is what I don’t want. Could anyone please explain me what am I doing wrong?

This config doesn't pick up myBehaviour extension and doesn't fail.

<system.serviceModel>
   <services>
      <service name="testService">
        <endpoint address="http://localhost:9999/TestServiceService"
                  binding="wsHttpBinding"
                  contract="ITestService "
                  behaviorConfiguration="myBehaviour"
                  />
        <endpoint address="mex"
                  binding="mexHttpBinding" 
                  contract="IMetadataExchange"
                  />
      </service>
  </services>
  <behaviors>
      <endpointBehaviors>
        <behavior name="myBehaviour">
          <HeaderForwardExtension />
        </behavior>
      </endpointBehaviors>
  </behaviors>
  <extensions>
     <behaviorExtensions>
        <add name="HeaderForwardExtension" type="Test.Service.HeaderForwardBehavior, Test.Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
     </behaviorExtensions>
  </extensions>
</system.serviceModel>

However removing

behaviorConfiguration="myBehaviour"

and changing behaviour tag so the name is not present

 <behavior>
    <HeaderForwardExtension />
 </behavior>

works just fine.

Thank you

Vojtiik
  • 2,558
  • 1
  • 17
  • 21
  • 1
    Sorry I have no idea where this comes from but your post just solved my problem of the last two days - I couldn't get my service to use a named behaviorExtension, but it doesn't matter for me if the extension is service-wide. – tomfumb Aug 16 '11 at 02:24

1 Answers1

0

Sounds like WCF doesn't pick up your service and endpoint config at all. Probably because your contract attribute has a space in it. So, WCF defaults to the default endpoint defined in machine config file, that causes default behaviors to be applied. Check your service and contract names, make sure they match your code.

http://blogs.msdn.com/b/endpoint/archive/2009/06/30/service-configuration-improvements-in-net-4.aspx

Sergey
  • 2,303
  • 1
  • 18
  • 11