WCF在防火墙后面出现wsDualHttpBinding和netTcpBinding问题

时间:2012-04-25 07:45:19

标签: wcf nettcpbinding wshttpbinding

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

由于wsDualHttpBinding的性质,如果客户端位于自己的防火墙之后,这显然无法工作。很自然地,netTcpBinding会想到应该解决双向问题。但奇怪的是,当服务配置XML更新为在相同端口上包含netTcpBinding(和/或排除wsDualHttpBinding)时,即使服务发现也不再有效

我想知道是否还有其他我想念的东西。我已经按照How to: Use netTcpBinding with Windows Authentication and Message Security in WCF Calling from Windows FormsWindows 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>

1 个答案:

答案 0 :(得分:3)

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