C#/ASP.NET - 远程服务器返回意外响应:(413) 请求实体太大
C#/ASP.NET - The remote server returned an unexpected response: (413) Request Entity Too Large
我正在尝试建立来自远程服务的响应。在我的 web.config 中使用以下部分,我收到来自 Web 服务的意外响应。
远程服务器返回意外响应:(413) 请求实体太大。我尝试增加缓冲区大小,但无法解决此错误。
我该如何解决这个问题?
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="CustomBinding_ISalesOrderService" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
<security mode="Transport"/>
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://app.vendsys2.com/VendSysAPI/v1.2/SalesOrderService.svc/VendSysAPI/v1.2/SalesReportService.svc"
binding="basicHttpBinding" bindingConfiguration="CustomBinding_ISalesOrderService"
contract="SalesOrderService.ISalesOrderService" name="CustomBinding_ISalesOrderService" />
</client>
</system.serviceModel>
如果客户端发送长 HTTP 请求,IIS 工作进程可能会收到足够的数据来解析请求 headers,但不会收到整个请求实体 body。当 IIS 工作进程检测到客户端证书需要 return 数据到客户端时,IIS 会尝试重新协商客户端连接。但是,客户端无法重新协商连接,因为它正在等待将剩余的请求数据发送到 IIS [1]。你的问题可能就是这样。
取自 Microsoft TechNet
If client renegotiation is requested, the request entity body must be preloaded using SSL preload. SSL preload will use the value of the UploadReadAheadSize metabase property, which is used for ISAPI extensions. However, if UploadReadAheadSize is smaller than the content length, an HTTP 413 error is returned, and the connection is closed to prevent deadlock. (Deadlock occurs because a client is waiting to complete sending a request entity, while the server is waiting for renegotiation to complete, but renegotiation requires that the client to be able to send data, which it cannot do).
The solution is to ensure that client is not blocked from sending the entire entity body. To do so, change the value of UploadReadAheadSize to a value larger than the content length.
The following example shows how to set the value for UploadReadAheadSize to 200KB on the Web server.
cscript adsutil.vbs set w3svc/1/uploadreadaheadsize 200
请注意,UploadReadAheadSize
元素已在 IIS 7 中删除,并作为属性添加到 serverRuntime
元素。
我正在尝试建立来自远程服务的响应。在我的 web.config 中使用以下部分,我收到来自 Web 服务的意外响应。
远程服务器返回意外响应:(413) 请求实体太大。我尝试增加缓冲区大小,但无法解决此错误。
我该如何解决这个问题?
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="CustomBinding_ISalesOrderService" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
<security mode="Transport"/>
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://app.vendsys2.com/VendSysAPI/v1.2/SalesOrderService.svc/VendSysAPI/v1.2/SalesReportService.svc"
binding="basicHttpBinding" bindingConfiguration="CustomBinding_ISalesOrderService"
contract="SalesOrderService.ISalesOrderService" name="CustomBinding_ISalesOrderService" />
</client>
</system.serviceModel>
如果客户端发送长 HTTP 请求,IIS 工作进程可能会收到足够的数据来解析请求 headers,但不会收到整个请求实体 body。当 IIS 工作进程检测到客户端证书需要 return 数据到客户端时,IIS 会尝试重新协商客户端连接。但是,客户端无法重新协商连接,因为它正在等待将剩余的请求数据发送到 IIS [1]。你的问题可能就是这样。
取自 Microsoft TechNet
If client renegotiation is requested, the request entity body must be preloaded using SSL preload. SSL preload will use the value of the UploadReadAheadSize metabase property, which is used for ISAPI extensions. However, if UploadReadAheadSize is smaller than the content length, an HTTP 413 error is returned, and the connection is closed to prevent deadlock. (Deadlock occurs because a client is waiting to complete sending a request entity, while the server is waiting for renegotiation to complete, but renegotiation requires that the client to be able to send data, which it cannot do).
The solution is to ensure that client is not blocked from sending the entire entity body. To do so, change the value of UploadReadAheadSize to a value larger than the content length.
The following example shows how to set the value for UploadReadAheadSize to 200KB on the Web server.
cscript adsutil.vbs set w3svc/1/uploadreadaheadsize 200
请注意,UploadReadAheadSize
元素已在 IIS 7 中删除,并作为属性添加到 serverRuntime
元素。