C#编码直接调用WCF服务时协议参数设置
C#编码直接调用WCF服务时协议参数设置
C#调用WCF服务时,需要设置协议,下面的代码介绍了C#调用WCF服务时协议的设置情况,具体代码如下:
PS: WCF大数量传输参数设置
C# Code:
private WSHttpBinding GetWSHttpBinding()
{
//wsHttpBinding
WSHttpBinding ws = new WSHttpBinding(SecurityMode.None);
ws.CloseTimeout = new TimeSpan(0, 1, 0);
ws.OpenTimeout = new TimeSpan(0, 1, 0);
ws.ReceiveTimeout = new TimeSpan(0, 20, 0);
ws.SendTimeout = new TimeSpan(0, 1, 0);
ws.BypassProxyOnLocal = false;
ws.TransactionFlow = false;
ws.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
ws.MaxBufferPoolSize = 524288; //获取或设置可为缓冲区管理器分配的最大内存量
ws.MaxReceivedMessageSize = 2147483647;//获取或设置可由绑定处理的消息的最大大小
ws.MessageEncoding = WSMessageEncoding.Text;
ws.TextEncoding = Encoding.UTF8;
ws.UseDefaultWebProxy = true;
ws.AllowCookies = false;
ws.ReaderQuotas.MaxDepth = 6553600;//Gets and sets the maximum nested node depth
ws.ReaderQuotas.MaxStringContentLength = 2147483647;//Gets and sets the maximum string length returned by the reader
ws.ReaderQuotas.MaxArrayLength = 6553600;//Gets and sets the maximum allowed array length
ws.ReaderQuotas.MaxBytesPerRead = 6553600;// Gets and sets the maximum allowed bytes returned for each read
ws.ReaderQuotas.MaxNameTableCharCount = 6553600;//Gets and sets the maximum characters allowed in a table name
ws.ReliableSession.Ordered = true;
ws.ReliableSession.InactivityTimeout = new TimeSpan(0, 20, 0);
ws.ReliableSession.Enabled = true;
ws.Security.Mode = SecurityMode.None;
ws.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
ws.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
ws.Security.Transport.Realm = "";
ws.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
ws.Security.Message.NegotiateServiceCredential = true;
ws.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Default;
ws.Security.Message.EstablishSecurityContext = false;
return ws;
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
private WSHttpBinding GetWSHttpBinding()
{
//wsHttpBinding
WSHttpBinding ws = new WSHttpBinding(SecurityMode.None);
ws.CloseTimeout = new TimeSpan(0, 1, 0);
ws.OpenTimeout = new TimeSpan(0, 1, 0);
ws.ReceiveTimeout = new TimeSpan(0, 20, 0);
ws.SendTimeout = new TimeSpan(0, 1, 0);
ws.BypassProxyOnLocal = false;
ws.TransactionFlow = false;
ws.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
ws.MaxBufferPoolSize = 524288; //获取或设置可为缓冲区管理器分配的最大内存量
ws.MaxReceivedMessageSize = 2147483647;//获取或设置可由绑定处理的消息的最大大小
ws.MessageEncoding = WSMessageEncoding.Text;
ws.TextEncoding = Encoding.UTF8;
ws.UseDefaultWebProxy = true;
ws.AllowCookies = false;
ws.ReaderQuotas.MaxDepth = 6553600;//Gets and sets the maximum nested node depth
ws.ReaderQuotas.MaxStringContentLength = 2147483647;//Gets and sets the maximum string length returned by the reader
ws.ReaderQuotas.MaxArrayLength = 6553600;//Gets and sets the maximum allowed array length
ws.ReaderQuotas.MaxBytesPerRead = 6553600;// Gets and sets the maximum allowed bytes returned for each read
ws.ReaderQuotas.MaxNameTableCharCount = 6553600;//Gets and sets the maximum characters allowed in a table name
ws.ReliableSession.Ordered = true;
ws.ReliableSession.InactivityTimeout = new TimeSpan(0, 20, 0);
ws.ReliableSession.Enabled = true;
ws.Security.Mode = SecurityMode.None;
ws.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
ws.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
ws.Security.Transport.Realm = "";
ws.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
ws.Security.Message.NegotiateServiceCredential = true;
ws.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Default;
ws.Security.Message.EstablishSecurityContext = false;
return ws;
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898

参考文档:
升级WCF后端通信架构,开发更简单高效!CSFrameworkV5.1旗舰版
WCF开发框架配置详解 WCF开发实例高级教程
WCF开发框架之Winform客户端配置文件 - App.config
WCF开发框架之WCF服务器配置文件 - Web.config
WCF错误“这可能是因为在HTTPS情况下使用HTTP.SYS未正确配置服务器证书”
C#源代码安全缺陷与提高源代码质量解决方案-WCF服务配置安全
WCF:SecurityNegotiationException 调用方未由服务进行身份验证
WCF采用Message安全模式运行出错:安全包中没有可用的凭证解决方案
WCF开发框架默认连接:HTTP协议+Message安全模式+Windows客户端认证
WCF顶级安全:HTTPS协议SSL证书+Windows认证+TransportWithMessageCredential安全模式
WCF开发框架-客户端采用Certificate认证模式调用基于HTTPS协议的WCF接口
调用WCF服务System.ServiceModel.ServiceActivationException:"无法激活请求的服务"
WCF开发框架-客户端采用Windows身份认证调用HTTPS协议WCF接口
WCF开发框架-客户端采用BASIC身份认证调用HTTPS协议WCF接口
vs使用透明代理工厂方式调用HTTPS协议的WCF服务
vs使用添加服务引用方式连接HTTPS协议的WCF服务
升级WCF后端通信架构,开发更简单高效!CSFrameworkV5.1旗舰版
WCF开发框架配置详解 WCF开发实例高级教程
WCF开发框架之Winform客户端配置文件 - App.config
WCF开发框架之WCF服务器配置文件 - Web.config
WCF错误“这可能是因为在HTTPS情况下使用HTTP.SYS未正确配置服务器证书”
C#源代码安全缺陷与提高源代码质量解决方案-WCF服务配置安全
WCF:SecurityNegotiationException 调用方未由服务进行身份验证
WCF采用Message安全模式运行出错:安全包中没有可用的凭证解决方案
WCF开发框架默认连接:HTTP协议+Message安全模式+Windows客户端认证
WCF顶级安全:HTTPS协议SSL证书+Windows认证+TransportWithMessageCredential安全模式
WCF开发框架-客户端采用Certificate认证模式调用基于HTTPS协议的WCF接口
调用WCF服务System.ServiceModel.ServiceActivationException:"无法激活请求的服务"
WCF开发框架-客户端采用Windows身份认证调用HTTPS协议WCF接口
WCF开发框架-客户端采用BASIC身份认证调用HTTPS协议WCF接口
vs使用透明代理工厂方式调用HTTPS协议的WCF服务
vs使用添加服务引用方式连接HTTPS协议的WCF服务
其它资料:
什么是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内容管理系统 |
在线客服
