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

扫一扫加作者微信


版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网