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

本文详细介绍了Windows Communication Foundation (WCF)服务的配置方法,包括服务端和客户端的配置实例。重点强调了binding名称一致性的重要性,并说明了security mode配置为None的情况。通过本文,读者可以了解如何正确配置WCF服务,避免出现服务器拒绝客户端凭据等问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

非常好用的C#.netTCP控件,this.vmTcpIpServer1.Collapse = false; this.vmTcpIpServer1.EnableLog = false; this.vmTcpIpServer1.IdleTime = -1; this.vmTcpIpServer1.LocalUsingIpAddr = "127.0.0.1"; this.vmTcpIpServer1.Location = new System.Drawing.Point(9, 17); this.vmTcpIpServer1.LogFilePath = "D:\\AppLog"; this.vmTcpIpServer1.MaxLogShownLines = 30; this.vmTcpIpServer1.Name = "vmTcpIpServer1"; this.vmTcpIpServer1.PackageHeader = UNYC.TcpIp.PackageHeader.None; this.vmTcpIpServer1.PackageTailer = UNYC.TcpIp.PackageTailer.None; this.vmTcpIpServer1.PortNum = 30000; this.vmTcpIpServer1.SaveToLogFile = false; this.vmTcpIpServer1.ShowTransContents = false; this.vmTcpIpServer1.Size = new System.Drawing.Size(266, 405); this.vmTcpIpServer1.TabIndex = 0; // // vmTcpIpClient1 // this.vmTcpIpClient1.AutoRecover = false; this.vmTcpIpClient1.Collapse = false; this.vmTcpIpClient1.ConnRetries = -1; this.vmTcpIpClient1.EnableLog = false; this.vmTcpIpClient1.IdleTime = -1; this.vmTcpIpClient1.IpAddr = "192.168.100.231"; this.vmTcpIpClient1.Location = new System.Drawing.Point(311, 17); this.vmTcpIpClient1.LogFilePath = "D:\\AppLog"; this.vmTcpIpClient1.MaxLogShownLines = 100; this.vmTcpIpClient1.Name = "vmTcpIpClient1"; this.vmTcpIpClient1.PackageHeader = UNYC.TcpIp.PackageHeader.None; this.vmTcpIpClient1.PackageTailer = UNYC.TcpIp.PackageTailer.None; this.vmTcpIpClient1.PingInterval = 500; this.vmTcpIpClient1.PortNum = 912815; this.vmTcpIpClient1.SaveToLogFile = false; this.vmTcpIpClient1.ShowTransContents = false; this.vmTcpIpClient1.Size = new System.Drawing.Size(266, 405);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值