C# 自承载 WCF 服务中的 HTTP 413 请求实体太大
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12491679/
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
HTTP 413 Request Entity Too Large In Self-Hosting WCF Service
提问by Fenton
I have a self-hosting WCF service accepting messages via HTTPS.
我有一个通过 HTTPS 接受消息的自托管 WCF 服务。
A message is being sent from a Java application, which receives the response:
正在从 Java 应用程序发送一条消息,该应用程序接收响应:
HTTP/1.1 413 Request Entity Too Large
Content-Length: 0
Server: Microsoft-HTTPAPI/2.0
Date: Wed, 19 Sep 2012 09:05:34 GMT
Connection: close
I am not attempting to upload a file, just send an XML/SOAP message, which is 78kb. I have tried upping my max message and buffer sizes but to no avail.
我没有尝试上传文件,只是发送 78kb 的 XML/SOAP 消息。我曾尝试增加我的最大消息和缓冲区大小,但无济于事。
<binding name="SecuredNoProxy" openTimeout="00:00:10" sendTimeout="00:00:10">
<textMessageEncoding messageVersion="Soap11WSAddressing10" />
<security includeTimestamp="true" enableUnsecuredResponse="true">
<localClientSettings timestampValidityDuration="00:15:00" />
</security>
<httpsTransport manualAddressing="false" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" allowCookies="false" bypassProxyOnLocal="true" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true" realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="false" requireClientCertificate="true" />
</binding>
Please let me know if I can supply any additional information.
如果我可以提供任何其他信息,请告诉我。
WCF Trace Log
WCF 跟踪日志
Receive bytes on connection 'https://localhost'
Activity boundary (Start)
Connection information
Throwing an exception (Error)
在连接“https://localhost”上接收字节
活动边界(开始)
连接信息
抛出异常(错误)
The exception is:
例外是:
System.ServiceModel.ProtocolException, System.ServiceModel, Version=4.0.0.0, Culture=neutral
System.ServiceModel.ProtocolException, System.ServiceModel, Version=4.0.0.0, Culture=neutral
采纳答案by Fenton
As I eluded to in the question, this is very much related to the binding configurations. In particular, maxReceivedMessageSize.
正如我在问题中所回避的,这与绑定配置非常相关。特别是 maxReceivedMessageSize。
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
This is the correct area to change (probably not to make things quite this big though as it will leave you potentially vulnerable to denial of service attacks). Determine a sensible value based on your actual messages.
这是要更改的正确区域(可能不要把事情搞得这么大,因为它可能会让您容易受到拒绝服务攻击)。根据您的实际消息确定一个合理的值。
The outbound endpoint was correctly configured but the inbound endpoint wasn't - it was:
出站端点已正确配置,但入站端点未正确配置 - 它是:
<httpsTransport requireClientCertificate="true" />
Which meant it was using the default value of 65536, which isn't enough for the message being sent. So it is really a case of checking the endpoints really carefully, especially if they are similarly named.
这意味着它使用了默认值65536,这对于正在发送的消息来说是不够的。所以这真的是一个非常仔细地检查端点的情况,特别是如果它们具有相似的名称。
回答by Jim Neff
For me it was maxRequestLength under system.web:
对我来说,它是 system.web 下的 maxRequestLength:
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
<httpRuntime
maxRequestLength="2147483647"
executionTimeout="300" />
</system.web>

