我遇到了可怕的
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上的属性,以便客户端和服务器增加它。我在代码中创建我的客户端,然后我试图以实物形式操纵这些属性。
这里我正在创建客户端,并将其分配给会话。我稍后会通过班级_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);
我改变了代码中的绑定,我可以在手表中看到这些值确实生效了。下面的_client是TestClient
之前创建并存储在Session
中的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);
。但是,错误仍然存在。还有我失踪的另一处房产吗?
{{1}}
答案 0 :(得分:0)
客户端和服务器绑定都需要
maxReceivedMessageSize
将您的值设置为Max是一个坏主意。您真的想尝试将其限制为您认为您的使用情况。除非你真的需要2gb文件传输,服务器才能处理它。