C# 以编程方式操纵WCF绑定,不起作用
我遇到了可怕的事情C# 以编程方式操纵WCF绑定,不起作用,c#,wcf,C#,Wcf,我遇到了可怕的事情 The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element. 错误。没问题,我知道您必须更改web.config上客户端和服务器的属性,才能将其增加。然而,我正在代码中创建我的客户机
The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
错误。没问题,我知道您必须更改web.config上客户端和服务器的属性,才能将其增加。然而,我正在代码中创建我的客户机,并且我正在尝试以实物方式操作这些属性
在这里,我创建客户机,并将其分配给会话。稍后我将通过类级别的\u client
字段调用它
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None);
binding.CloseTimeout = new TimeSpan(00, 05, 00);
binding.OpenTimeout = new TimeSpan(00, 05, 00);
binding.ReceiveTimeout = new TimeSpan(00, 05, 00);
binding.SendTimeout = new TimeSpan(00, 05, 00);
binding.TextEncoding = System.Text.Encoding.UTF8;
binding.MaxReceivedMessageSize = int.MaxValue;
binding.MaxBufferSize = int.MaxValue;
binding.MaxBufferPoolSize = int.MaxValue;
binding.Name = "BasicHttpBinding_Test";
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
EndpointAddress endpointAddress = new EndpointAddress(wcfUrl);
HttpContext.Current.Session["Client"] = new TestClient(binding, endpointAddress);
我在代码中更改了绑定,我可以在手表中看到这些值确实正在生效。下面的_客户机是以前创建并存储在会话中的TestClient
。但是,错误仍然存在。我还缺少其他财产吗
Binding binding = _client.Endpoint.Binding;
binding.CloseTimeout = new TimeSpan(00, 05, 00);
binding.OpenTimeout = new TimeSpan(00, 05, 00);
binding.ReceiveTimeout = new TimeSpan(00, 05, 00);
binding.SendTimeout = new TimeSpan(00, 05, 00);
binding.GetType().GetProperty("ReaderQuotas").SetValue(binding, XmlDictionaryReaderQuotas.Max, null);
binding.GetType().GetProperty("TransferMode").SetValue(binding, TransferMode.Streamed, null);
binding.GetType().GetProperty("MaxBufferPoolSize").SetValue(binding, int.MaxValue, null);
binding.GetType().GetProperty("MaxBufferSize").SetValue(binding, int.MaxValue, null);
binding.GetType().GetProperty("MaxReceivedMessageSize").SetValue(binding, int.MaxValue, null);
客户端和服务器绑定都需要
maxReceivedMessageSize
将值设置为Max是个坏主意。你真的想试着把它限制在你认为你的使用量之内。除非你真的需要2gb的文件传输,而且服务器可以处理