WCF netTcpBinding跨主机通讯问题

采用NetTcpBinding绑定方式,一旦跨主机就会提示:服务器已拒绝客户端凭据

需要在Host和Client的App.config中进行一下安全配置:

一、Host App.config配置

粘上完整的:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <system.serviceModel>

    <services>

      <service name="TESTWCF.MyData.MyDataService" behaviorConfiguration="serviceBehavior">

        <endpoint binding="netTcpBinding" contract="TESTWCF.MyData.IMyDataService" address="MyData"  bindingConfiguration="Binding1"  />

        <host>

          <baseAddresses>

            <add baseAddress="net.tcp://192.168.0.2:8123"/>

          </baseAddresses>

        </host>

      </service>

    </services>

    

    <bindings>

      <netTcpBinding>

        <binding name="Binding1">

          <security mode="None">

            <transport clientCredentialType="Windows" />

            <message clientCredentialType="Windows" />

          </security>

        </binding>

      </netTcpBinding>

    </bindings>

    

    <behaviors>

      <serviceBehaviors>

        <behavior name="serviceBehavior">

        </behavior>

      </serviceBehaviors>

    </behaviors>

  </system.serviceModel>

</configuration>

 

其中下面的为增加的:

    <bindings>

      <netTcpBinding>

        <binding name="Binding1">

          <security mode="None">

            <transport clientCredentialType="Windows" />

            <message clientCredentialType="Windows" />

          </security>

        </binding>

      </netTcpBinding>

    </bindings>

并且要在EndPoint后增加 :bindingConfiguration="Binding1"

到此服务端配置完成

二、Client App.config配置

在EndPoint后增加:bindingConfiguration="Binding1"

并把上面<bindings> …</bindings> 复制过去。

 

这样即可跨主机通讯了。

MSDN:http://msdn.microsoft.com/zh-cn/library/ms731343.aspx

你可能感兴趣的:(bind)