防火墙后面的 wsDualHttpBinding 和 netTcpBinding 的 WCF 问题

标签 wcf nettcpbinding wshttpbinding

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

由于 wsDualHttpBinding 的性质,如果客户端位于其自己的防火墙后面,这显然无法工作。因此,很自然地,我想到了 netTcpBinding,它应该可以解决双向问题。但奇怪的是,当服务配置 XML 更新为在相同端口上包含 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>

最佳答案

如果您只能使用单个端口并且必须使用 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

关于防火墙后面的 wsDualHttpBinding 和 netTcpBinding 的 WCF 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10311446/

相关文章:

wcf - netTcpBinding 或 wsHttpBinding

.net - 如何在服务根地址(不带尾部斜杠)托管 WCF REST 服务?

wcf - 我可以将 WCF wsHttpContextBinding 与 WSIT (Metro) 客户端一起使用吗?

entity-framework - 使用 EF 的数据服务 - 是否可以使用返回自定义类型的 WebGet 方法?

asp.net - 在 IIS 7 上配置 WCF/NET.TCP,net.tcp 状态旁边的 "Unknown"?

c# - 加载多个数据时 WCF 服务 channel 中的 CommunicationObjectAbortedException

wcf - 哪个工具可以检查WCF tcp传输是否真正加密

.net - SOA : WCF 中转换层的替代方案

wcf - 数据协定中的扩展方法

WCF 在客户端和服务器上都有证书(消息安全和 wsHttpBinding)