C# 如何不限制 maxBufferSize 和 maxReceivedMessageSize
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18955772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to make no limit on maxBufferSize and maxReceivedMessageSize
提问by user1958628
I have an ASP.NET (C#) 4.0 WCF application. I got message error:
我有一个 ASP.NET (C#) 4.0 WCF 应用程序。我收到消息错误:
Error : 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.
错误:已超出传入邮件的最大邮件大小配额 (65536)。要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性。
I have increased it into
我已将其增加为
maxBufferSize="2097152" maxBufferPoolSize="524288" maxReceivedMessageSize="2097152"
it works fine. But I am afraid that next time may be it will be over the quota again.
它工作正常。但恐怕下一次可能会再次超过配额。
Can I set this maxBufferSize
and maxReceivedMessageSize
with no limit ?
我可以设置这个maxBufferSize
并且maxReceivedMessageSize
没有限制吗?
thanks you in advance
提前谢谢你
回答by marc_s
You cannot set it to "no limit" - how would you handle a limitlessly large message, anyway?
您不能将其设置为“无限制” - 无论如何,您将如何处理无限大的消息?
The maximum you can set it to is 2 billion (int.MaxValue
in .NET) - which corresponds to 2 GB (2'147'483'648 bytes) of data.
您可以将其设置为 20 亿(int.MaxValue
在 .NET 中) - 这对应于 2 GB(2'147'483'648 字节)的数据。
Is that enough for your needs?
这足以满足您的需求吗?
回答by Brian
Also, if you're maxing out your buffer with big uploads or downloads, consider streaming as an alternative.
此外,如果您通过大量上传或下载来最大化缓冲区,请考虑将流式传输作为替代方案。
回答by Habib
Can I set this maxBufferSize and maxReceivedMessageSize with no limit ?
我可以无限制地设置这个 maxBufferSize 和 maxReceivedMessageSize 吗?
No.You can not do that.
号你不能做到这一点。
Set your values to Max like:
将您的值设置为 Max,例如:
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
MaxBufferSizeis of type int
. So the max value it can support is Int32.MaxValue(2147483647) to avail the maximum allowable size. (Int.MaxValue
is just one byte shy of 2 GB of data)
MaxBufferSize的类型为int
。所以它可以支持的最大值是Int32.MaxValue(2147483647) 以利用最大允许大小。(Int.MaxValue
仅比 2 GB 数据少 1 个字节)
MaxReceivedMessageSizeon the other hand is of type long
or Int64
and the max value it supports is: 9,223,372,036,854,775,807
MaxReceivedMessageSize另一方面是long
or类型Int64
,它支持的最大值是:9,223,372,036,854,775,807
回答by aemre
You should change buffersize, if you're using dynamically use this code
您应该更改缓冲区大小,如果您使用动态使用此代码
var binding = new BasicHttpBinding();
binding.ProxyAddress = new Uri(string.Format("http://{0}:{1}", proxyAddress, proxyPort));
binding.UseDefaultWebProxy = false;
binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.MaxReceivedMessageSize = Int32.MaxValue; //IMPORTANT
binding.MaxBufferSize = Int32.MaxValue; //IMPORTANT
binding.MaxBufferPoolSize = Int32.MaxValue;//IMPORTANT
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;
if you're using webconfig use this code
如果您使用 webconfig 使用此代码
<bindings>
<basicHttpBinding>
<binding name="basicHttp" allowCookies="true"
maxReceivedMessageSize="20000000"
maxBufferSize="20000000"
maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32"
maxArrayLength="200000000"
maxStringContentLength="200000000"/>
</binding>
</basicHttpBinding>