代码之家  ›  专栏  ›  技术社区  ›  Damian Powell

如何强制net.tcp mex端点(mexTcpBinding)参与端口共享?

  •  11
  • Damian Powell  · 技术社区  · 14 年前

    我有一个作为Windows服务托管的WCF服务。我们希望在同一地址启用一个mex端点(但后缀为“/mex”)。我一直在尝试使用以下配置执行此操作(未成功):

    <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 端点以及请求在此计算机上共享该端口的任何其他服务。

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

    这意味着mex端点现在有自己的独占端口。这样做的缺点是,任何其他想要公开mex端点的服务也需要为其mex端点提供一个唯一的端口。这使得在查找mex端点时非常不可预测。

    1 回复  |  直到 6 年前
        1
  •  8
  •   ErnieL    14 年前

    两种选择:

    1. 简单的方法是:将mex的整个绑定更改为netTcpBinding,并让它重用您的绑定配置。mexTCPBinding只是为了方便起见,是可选的。如果它不适合你,就不要用它。

    2. http://blogs.msdn.com/b/drnick/archive/2006/08/23/713297.aspx