如何强制net.tcp混合端点(mexTcpBinding)参与端口共享? [英] How to force a net.tcp mex endpoint (mexTcpBinding) to participate in port sharing?

查看:69
本文介绍了如何强制net.tcp混合端点(mexTcpBinding)参与端口共享?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WCF服务,该服务作为Windows服务托管.我们想在同一地址启用一个mex端点(但后缀为'/mex').我一直在尝试使用以下配置执行此操作(失败):

I have a WCF service which is hosted as a Windows Service. We would like to enable a mex endpoint at the same address (but with a '/mex' suffix). I have been trying to do this (unsuccessfully) using the following configuration:

<system.serviceModel>

  <services>
    <service
      name="MyCompany.MyService"
      behaviorConfiguration="defaultServiceBehavior">

      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost"/>
        </baseAddresses>
      </host>

      <endpoint
        address="MyService"
        binding="netTcpBinding"
        contract="MyCompany.IMyService"
        bindingConfiguration="netTcpBindingConfig"
        />

      <endpoint
        address="MyService/mex"
        binding="mexTcpBinding"
        contract="IMetadataExchange"
        />

    </service>
  </services>

  <behaviors>
    <serviceBehaviors>
      <behavior name="defaultServiceBehavior">
        <serviceMetadata />
      </behavior>
    </serviceBehaviors>
  </behaviors>

  <bindings>
    <netTcpBinding>
      <binding name="netTcpBindingConfig" portSharingEnabled="true" />
    </netTcpBinding>
  </bindings>

</system.serviceModel>

运行时,服务主机抛出AddressAlreadyInUseException,抱怨"IP端点0.0.0.0:808上已经有一个侦听器".这实际上对我来说是有意义的,因为端口共享服务已打开该端口以便与MyService端点一起使用,并与其他请求在此计算机上共享该端口的其他服务一起使用.

When it runs, the service host throws an AddressAlreadyInUseException complaining that "There is already a listener on IP endpoint 0.0.0.0:808". This actually makes sense to me because the port sharing service has opened that port in order to serve the MyService endpoint along with any other services requesting to share that port on this machine.

因此,似乎mex端点想要对端口808的独占访问.我可以通过调整mex端点来解决此问题,如下所示:

So it seems that the mex endpoint wants exlusive access to port 808. I can work around this by tweaking the mex endpoint like so:

<endpoint
  address="net.tcp://localhost:818/MyService/mex"
  binding="mexTcpBinding"
  contract="IMetadataExchange"
  />

这意味着mex端点现在具有其自己的独占端口.这样做的缺点是,任何其他想要公开mex终结点的服务也将需要一个唯一的端口作为其mex终结点.这在寻找mex端点时非常不可预测.

This means that the mex endpoint now has its own exclusive port. The downside with this is that any other service which wants to expose a mex endpoint will also need a unique port for its mex endpoint. This makes it very unpredictable when looking for mex endpoints.

是否有一种方法可以强制mex端点参与端口共享?

Is there a way to force the mex endpoint to participate in port sharing?

推荐答案

两个选项:

  1. 简单方法:将mex点的整个绑定更改为netTcpBinding,并重新使用您的bindingConfiguration. mexTCPBinding只是为了方便起见,是可选的.如果它不适合您,请不要使用它.

  1. The easy way: Change the entire binding for the mex point to netTcpBinding and have it reuse your bindingConfiguration. mexTCPBinding is only meant to be a convenience and is optional. If its not working for you, don’t use it.

困难的方法:您可以修改mexTCPBinding以启用共享.我见过的唯一示例在下面的代码中: http://blogs. msdn.com/b/drnick/archive/2006/08/23/713297.aspx

The hard way: You can modify the mexTCPBinding to enable sharing. The only example I’ve seen is in code here: http://blogs.msdn.com/b/drnick/archive/2006/08/23/713297.aspx

这篇关于如何强制net.tcp混合端点(mexTcpBinding)参与端口共享?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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