【问题标题】:WCF issues with wsDualHttpBinding and netTcpBinding behind firewalls防火墙后面的 wsDualHttpBinding 和 netTcpBinding 的 WCF 问题
【发布时间】:2012-04-25 07:45:19
【问题描述】:

我有一个独立的 WCF 服务在防火墙后面的服务器上运行。它目前使用wsDualHttpBinding,因为该服务使用回调。客户端在 LAN 环境中工作正常。我们已打开防火墙以允许自定义端口上的流量,因此现在可以从外部 LAN 发现服务。

由于wsDualHttpBinding 的性质,如果客户端位于自己的防火墙后面,这显然无法工作。所以很自然地,netTcpBinding 浮现在脑海中,它应该可以解决双向问题。但奇怪的是,当服务配置 XML 更新为在 same 端口上包含 netTcpBinding(和/或排除 wsDualHttpBinding)时,甚至服务发现也不再起作用。

我想知道我是否还缺少其他任何东西。我已遵循 How to: Use netTcpBinding with Windows Authentication and Message Security in WCF Calling from Windows Forms 和 Windows Communication Foundation QuickStart - Multiple Binding VS2010 的确切配置建议。

配置:

<system.serviceModel>
  <bindings>
    <netTcpBinding>
      <binding name="NetTcpBindingEndpointConfig">
        <security mode="Message" />
      </binding>
    </netTcpBinding>
  </bindings>
  <services>
    <service name="Service1.Service1.Service">
      <endpoint address="Service1" binding="wsDualHttpBinding" contract="Service1.IService1">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      <endpoint address="" binding="netTcpBinding"
                 bindingConfiguration="NetTcpBindingEndpointConfig"
                 name="NetTcpBindingEndpoint" contract="Service1.IService1">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:9999/Service1.Service1/"/>
          <add baseAddress="net.tcp://localhost:9999/Service1.Service1/" />
        </baseAddresses>
      </host>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <!-- To avoid disclosing metadata information, 
        set the value below to false and remove the metadata endpoint above before deployment -->
        <serviceMetadata httpGetEnabled="True"/>
        <!-- To receive exception details in faults for debugging purposes, 
        set the value below to true.  Set to false before deployment 
        to avoid disclosing exception information -->
        <serviceDebug includeExceptionDetailInFaults="True"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

【问题讨论】:

  • 服务发现到底是什么意思?您是否使用 WCF 4 中的 WS-Discovery 机制?
  • 不,我可能使用了错误的术语。对于“发现”,我的意思是添加服务引用是成功的。
  • 显示整个服务配置。
  • 如果你想暴露两个基地址,你必须为 http 和 net.tcp 使用不同的端口。
  • 好的,谢谢。我真的给你发了一个旧的配置。但是考虑wsDualHttpBinding 及其基地址被完全注释掉(或删除)所以只剩下netTcpBinding 的场景。为什么那行不通?

标签: wcf nettcpbinding wshttpbinding


【解决方案1】:

如果您只能使用单个端口并且必须使用 netTcpBinding,请尝试以这种方式配置您的服务:

<system.serviceModel>
  <bindings>
    <netTcpBinding>
      <binding name="NetTcpBindingEndpointConfig">
        <security mode="Message" />
      </binding>
    </netTcpBinding>
  </bindings>
  <services>
    <service name="Service1.Service1.Service">
      <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
      <endpoint address="" binding="netTcpBinding"
                 bindingConfiguration="NetTcpBindingEndpointConfig"
                 name="NetTcpBindingEndpoint" contract="Service1.IService1">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost:9999/Service1.Service1/" />
        </baseAddresses>
      </host>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata httpGetEnabled="False"/>
        <serviceDebug includeExceptionDetailInFaults="True"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

添加服务引用时尝试使用此地址:

net.tcp://localhost:9999/Service1.Service1/mex

【讨论】:

  • 让我补充一点,我的特定场景有多个托管在一堆服务中,因此显然存在端口冲突。幸运的是,我找到了this,它帮助我意识到我的binding 上也需要portSharingEnabled="true"。我还更改了mex 以使用相同的共享netTcpBinding。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-22
  • 1970-01-01
  • 2011-12-22
  • 1970-01-01
  • 2011-01-04
  • 1970-01-01
  • 2010-09-26
相关资源
最近更新 更多