WCF 通过net tcp 协议 ,在服务端服务器和客户端服务器之间传输数据,注意配置事项

1. 特别注意  binding name="BindingBehaviorConfiguration" (名字可以随意取,但是必须要服务端和客户端保持一致

    bindingConfiguration="BindingBehaviorConfiguration"

  如何没有配置保持一致:出现:服务器已拒绝客户端凭据   

    如果没有配置:security mode="None", 出现的现象:服务器已拒绝客户端凭据

//----服务端配置实例:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>

<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="BindingBehaviorConfiguration" maxBufferPoolSize="52428800"
maxBufferSize="6553600" maxReceivedMessageSize="6553600" portSharingEnabled="true">
<readerQuotas maxStringContentLength="6553600" />
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="CDAgentWCF.Services.CDAgentWCFService" behaviorConfiguration="CDAgentWCF.Services.CDAgentWCFServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:9999/CDAgentWCF"/>
<add baseAddress="http://localhost:9998/CDAgentWCF"/>
</baseAddresses>
</host>
<endpoint address="PropellingService"
binding="netTcpBinding"
contract="CDAgentWCF.Services.ICDAgentWCFService" bindingConfiguration="BindingBehaviorConfiguration" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CDAgentWCF.Services.CDAgentWCFServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>

</system.serviceModel>
</configuration>


客户端配置实例:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="BindingBehaviorConfiguration">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://192.168.1.88:9999/CDAgentWCF/PropellingService"
binding="netTcpBinding"
contract="CDAgentService.CDAgentWCFService" bindingConfiguration="BindingBehaviorConfiguration">
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

原文地址:https://www.cnblogs.com/jeff20120716/p/4598329.html