加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c#-4.0 – WCF:TCP.NET上的多个绑定

发布时间:2020-12-15 21:18:56 所属栏目:百科 来源:网络整理
导读:我试图在IIS 7.5下建立一个具有多个tcp.net绑定的网站. 由于服务是在负载均衡器后面,我需要多个服务端点: log.o1881.no/log/service.svc log.core1.o1881.no/log/service.svc 这在我在web.config中配置时适用于http绑定: system.serviceModel serviceHosti
我试图在IIS 7.5下建立一个具有多个tcp.net绑定的网站.

由于服务是在负载均衡器后面,我需要多个服务端点:

log.o1881.no/log/service.svc

log.core1.o1881.no/log/service.svc

这在我在web.config中配置时适用于http绑定:

<system.serviceModel>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

将以下tcp.net绑定添加到站点时,将显示以下错误消息:

808:log.o1881.no

808:log.core1.o1881.no

‘/ Log’应用程序中的服务器错误.

此集合已包含方案net.tcp的地址.此集合中每个方案最多只能有一个地址.如果您的服务是在IIS中托管的,则可以通过将’system.serviceModel / serviceHostingEnvironment / multipleSiteBindingsEnabled’设置为true或指定’system.serviceModel / serviceHostingEnvironment / baseAddressPrefixFilters’来解决问题.
参数名称:item

我还尝试将其添加到web.config:

<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
  <baseAddressPrefixFilters>
    <add prefix="net.tcp://log.o1881.no:808/log" />
    <add prefix="net.tcp://log.core1.o1881.no:808/log" />
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>

但这不起作用.

由于该服务将部署在多个服务器上,我非常希望能够通过配置和IIS设置来完成这项工作,而不是代码.

这是可能做的,还是有另一种方法来处理这种情况(http和net.tcp上的多个绑定名称,由于负载均衡)?

解决方法

根据 documentation,使用multipleSiteBindingsEnabled告诉WCF忽略任何< baseAddressPrefixFilters>.

“当使用此设置启用多个站点绑定时,对于HTTP和非HTTP协议,将忽略任何baseAddressPrefixFilters设置.”

因此,这个配置与自身相矛盾,您指定地址前缀并同时指示WCF忽略它们,因为您指定了multipleSiteBindingsEnabled.

<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
  <baseAddressPrefixFilters>
    <add prefix="net.tcp://log.o1881.no:808/log" />
    <add prefix="net.tcp://log.core1.o1881.no:808/log" />
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>

我认为multipSiteBindingsEnabled最适合您只对使用HTTP方案感兴趣的场景.

否则不要使用它,实际上你可以在同一个IIS站点/应用程序层次结构中的不同端口上有多个tcp.net绑定.

<serviceHostingEnvironment>
  <baseAddressPrefixFilters>
    <add prefix="net.tcp://log.o1881.no:808/log" />
    <add prefix="net.tcp://log.core1.o1881.no:808/log" />
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>

希望这有助于其他人:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读