WCF开发框架 - NetTcpBinding配置web.config与C#代码配置
WCF开发框架 - NetTcpBinding配置web.config与C#代码配置
XML Code:
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
maxBufferSize="1048576" maxConnections="10" maxReceivedMessageSize="1048576">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Transport" protectionLevel="None">
</transport>
<message clientCredentialType="None" />
</security>
</binding>
</netTcpBinding>
</bindings>
//来源:C/S框架网 | www.csframework.com | QQ:23404761
<netTcpBinding>
<binding name="NetTcpBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
maxBufferSize="1048576" maxConnections="10" maxReceivedMessageSize="1048576">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Transport" protectionLevel="None">
</transport>
<message clientCredentialType="None" />
</security>
</binding>
</netTcpBinding>
</bindings>
//来源:C/S框架网 | www.csframework.com | QQ:23404761
创建NetTcpBinding协议绑定
C# Code:
/// <summary>
/// 创建NetTcpBinding协议绑定
/// </summary>
/// <param name="https"></param>
/// <returns></returns>
public static NetTcpBinding CreateNetTcpBinding(bool https = false)
{
NetTcpBinding ws = new NetTcpBinding();
ws.Name = "NetTcpBinding";
ws.MaxReceivedMessageSize = 2147483647;//最大接收的消息大小
ws.MaxBufferSize = 2147483647;// 从通道接收消息的缓存大小
ws.MaxBufferPoolSize = 2147483647;//从通道接收消息的最大缓存数量
ws.CloseTimeout = new TimeSpan(0, 10, 0);
ws.OpenTimeout = new TimeSpan(0, 10, 0);
ws.SendTimeout = new TimeSpan(0, 10, 0);
ws.ReceiveTimeout = new TimeSpan(0, 10, 0);
ws.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
ws.PortSharingEnabled = false;//获取或设置一个值,该值指示是否为采用此绑定配置的连接启用 TCP 端口共享。
//ws.MaxConnections = 256;//如果修改maxConnections的值,服务会导致不正常,会报端口已经被占用
//ws.ListenBacklog = 10;
ws.TransferMode = TransferMode.Buffered;
ws.TransactionProtocol = TransactionProtocol.OleTransactions;
ws.TransactionFlow = false;
ws.ReliableSession.Ordered = true;
ws.ReliableSession.InactivityTimeout = new TimeSpan(0, 10, 0);
//security节点配置 - HTTPS 协议配置
if (https)
{
ws.Security.Mode = SecurityMode.Transport;
ws.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
ws.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.None;
}
else
{
//security节点配置 - HTTP协议配置
ws.Security.Mode = SecurityMode.None;
ws.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
ws.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.None;
}
System.Xml.XmlDictionaryReaderQuotas rq = ws.ReaderQuotas;
rq.MaxArrayLength = 2147483647;//最大数组长度
rq.MaxBytesPerRead = 6553600;//最大每次读取长度
rq.MaxDepth = 6553600;// 最大节点深度
rq.MaxNameTableCharCount = 6553600;//最大NameTableChar的数量
rq.MaxStringContentLength = 2147483647;// 最大内容长度
return ws;
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// <summary>
/// 创建NetTcpBinding协议绑定
/// </summary>
/// <param name="https"></param>
/// <returns></returns>
public static NetTcpBinding CreateNetTcpBinding(bool https = false)
{
NetTcpBinding ws = new NetTcpBinding();
ws.Name = "NetTcpBinding";
ws.MaxReceivedMessageSize = 2147483647;//最大接收的消息大小
ws.MaxBufferSize = 2147483647;// 从通道接收消息的缓存大小
ws.MaxBufferPoolSize = 2147483647;//从通道接收消息的最大缓存数量
ws.CloseTimeout = new TimeSpan(0, 10, 0);
ws.OpenTimeout = new TimeSpan(0, 10, 0);
ws.SendTimeout = new TimeSpan(0, 10, 0);
ws.ReceiveTimeout = new TimeSpan(0, 10, 0);
ws.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
ws.PortSharingEnabled = false;//获取或设置一个值,该值指示是否为采用此绑定配置的连接启用 TCP 端口共享。
//ws.MaxConnections = 256;//如果修改maxConnections的值,服务会导致不正常,会报端口已经被占用
//ws.ListenBacklog = 10;
ws.TransferMode = TransferMode.Buffered;
ws.TransactionProtocol = TransactionProtocol.OleTransactions;
ws.TransactionFlow = false;
ws.ReliableSession.Ordered = true;
ws.ReliableSession.InactivityTimeout = new TimeSpan(0, 10, 0);
//security节点配置 - HTTPS 协议配置
if (https)
{
ws.Security.Mode = SecurityMode.Transport;
ws.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
ws.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.None;
}
else
{
//security节点配置 - HTTP协议配置
ws.Security.Mode = SecurityMode.None;
ws.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
ws.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.None;
}
System.Xml.XmlDictionaryReaderQuotas rq = ws.ReaderQuotas;
rq.MaxArrayLength = 2147483647;//最大数组长度
rq.MaxBytesPerRead = 6553600;//最大每次读取长度
rq.MaxDepth = 6553600;// 最大节点深度
rq.MaxNameTableCharCount = 6553600;//最大NameTableChar的数量
rq.MaxStringContentLength = 2147483647;// 最大内容长度
return ws;
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761

参考文档:
WCF开发框架 - BasicHttpBinding绑定的web.config与C#代码配置(支持https协议)
WCF开发框架之WCF服务器配置文件 - Web.config
WCF快速开发框架 - IIS承载WCF net.tcp协议NetTcpBinding配置详解
WCF开发框架之WSHttpBinding参数配置(C#代码配置+App.Config两种方案)
WCF开发框架配置详解 WCF开发实例高级教程
WCF快速开发框架 - IIS承载WCF服务wsHttpBindings配置详解(HTTP协议)
WCF快速开发框架 - IIS承载WCF http协议BasicTcpBinding配置详解
WCF开发框架之Winform客户端配置文件 - App.config
Winform企业级WCF快速开发框架平台(C/S架构+WCF+DevExpress+SQL多数据库)
WCF开发框架默认连接:HTTP协议+Message安全模式+Windows客户端认证
WCF开发框架-客户端采用Certificate认证模式调用基于HTTPS协议的WCF接口
WCF开发框架-客户端采用Windows身份认证调用HTTPS协议WCF接口
WCF开发框架-客户端采用BASIC身份认证调用HTTPS协议WCF接口
【原创】WCF开发框架 - 采用wsHttpBinding及basicHttpBinding连接https协议的WCF服务
WCF开发框架 - vs发布IIS承载(IIS Hosting)的WCF应用服务详解
VS开发环境配置-C/S开发框架
WCF开发框架 - BasicHttpBinding绑定的web.config与C#代码配置(支持https协议)
WCF开发框架之WCF服务器配置文件 - Web.config
WCF快速开发框架 - IIS承载WCF net.tcp协议NetTcpBinding配置详解
WCF开发框架之WSHttpBinding参数配置(C#代码配置+App.Config两种方案)
WCF开发框架配置详解 WCF开发实例高级教程
WCF快速开发框架 - IIS承载WCF服务wsHttpBindings配置详解(HTTP协议)
WCF快速开发框架 - IIS承载WCF http协议BasicTcpBinding配置详解
WCF开发框架之Winform客户端配置文件 - App.config
Winform企业级WCF快速开发框架平台(C/S架构+WCF+DevExpress+SQL多数据库)
WCF开发框架默认连接:HTTP协议+Message安全模式+Windows客户端认证
WCF开发框架-客户端采用Certificate认证模式调用基于HTTPS协议的WCF接口
WCF开发框架-客户端采用Windows身份认证调用HTTPS协议WCF接口
WCF开发框架-客户端采用BASIC身份认证调用HTTPS协议WCF接口
【原创】WCF开发框架 - 采用wsHttpBinding及basicHttpBinding连接https协议的WCF服务
WCF开发框架 - vs发布IIS承载(IIS Hosting)的WCF应用服务详解
VS开发环境配置-C/S开发框架
其它资料:
什么是C/S结构? | C/S框架核心组成部分 | C/S框架-WebService部署图 | C/S框架-权限管理 | C/S结构系统框架 - 5.1旗舰版介绍 | C/S结构系统框架 - 功能介绍 | C/S结构系统框架 - 产品列表 | C/S结构系统框架 - 应用展示(图) | 三层体系架构详解 | C/S架构轻量级快速开发框架 | C/S框架网客户案例 | WebApi快速开发框架 | C/S框架代码生成器 | 用户授权注册软件系统 | 版本自动升级软件 | 数据库底层应用框架 | CSFramework.CMS内容管理系统 |
什么是C/S结构? | C/S框架核心组成部分 | C/S框架-WebService部署图 | C/S框架-权限管理 | C/S结构系统框架 - 5.1旗舰版介绍 | C/S结构系统框架 - 功能介绍 | C/S结构系统框架 - 产品列表 | C/S结构系统框架 - 应用展示(图) | 三层体系架构详解 | C/S架构轻量级快速开发框架 | C/S框架网客户案例 | WebApi快速开发框架 | C/S框架代码生成器 | 用户授权注册软件系统 | 版本自动升级软件 | 数据库底层应用框架 | CSFramework.CMS内容管理系统 |
在线客服
