WCF endpointBehaviors extension not picked up when the name param is present?

旧时模样 提交于 2019-12-07 09:38:12

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/4015376/wcf-endpointbehaviors-extension-not-picked-up-when-the-name-param-is-present

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!