存在名称参数时未选择 WCF endpointBehaviors 扩展? [英] WCF endpointBehaviors extension not picked up when the name param is present?

查看:12
本文介绍了存在名称参数时未选择 WCF endpointBehaviors 扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用自定义 MessageInspector 扩展我的服务端点行为,扩展工作正常并被拾取,但前提是我没有在行为标签上定义名称"参数并且没有在端点上定义特定的行为配置.这意味着我要扩展所有端点,而这正是我不想要的.谁能解释一下我做错了什么?

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?

此配置不会选择 myBehaviour 扩展并且不会失败.

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>

但是删除

behaviorConfiguration="myBehaviour"

并更改行为标签,因此名称不存在

and changing behaviour tag so the name is not present

 <behavior>
    <HeaderForwardExtension />
 </behavior>

工作正常.

谢谢

推荐答案

听起来 WCF 根本不接受您的服务和端点配置.可能是因为您的合同属性中有一个空格.因此,WCF 默认使用机器配置文件中定义的默认端点,这会导致应用默认行为.检查您的服务和合同名称,确保它们与您的代码匹配.

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

这篇关于存在名称参数时未选择 WCF endpointBehaviors 扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆