(413)请求实体太大|应将UploadReadAheadSize [英] (413) Request Entity Too Large | uploadReadAheadSize

查看:1850
本文介绍了(413)请求实体太大|应将UploadReadAheadSize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用.NET 4.0编写了一个WCF服务,它使用IIS 7.5托管在我的Windows 7 x64 Ultimate系统上。
其中一个服务方法有一个'object'作为参数,我试图发送一个包含图片的byte []。
只要此图片的文件大小小于约。 48KB,一切顺利。但是,如果我尝试上传更大的图片,WCF服务会返回错误:(413)请求实体太大。
所以当然我已经花了3小时谷歌搜索错误消息和我见过的关于这个主题的每个主题建议提高'uploadReadAheadSize'属性。
所以我所做的就是使用以下命令(10485760 = 10MB):

I've written a WCF service with .NET 4.0, which is hosted on my Windows 7 x64 Ultimate system with IIS 7.5. One of the service methods has an 'object' as argument and I'm trying to send a byte[] which contains a picture. As long as the file size of this picture is less then approx. 48KB, all goes well. But if I'm trying to upload a larger picture, the WCF service returns an error: (413) Request Entity Too Large. So ofcourse I've spent 3 hours Googling the error message and every topic I've seen about this subject suggests raising the 'uploadReadAheadSize' property. So what I've done is using the following commands (10485760 = 10MB):

appcmd.exe set config -section :system.webserver / serverruntime / uploadreadaheadsize:10485760 / commit:apphost

cscript adsutil.vbs set w3svc /< APP_ID> / uploadreadaheadsize 10485760

我还使用IIS管理器通过打开网站设置值并转到配置编辑器在管理下。
不幸的是我仍然收到Request Entity Too Large错误而且它真的很令人沮丧!

I've also used IIS Manager to set the value by opening the site and going to "Configuration Editor" under Management. Unfortunately I'm still getting the Request Entity Too Large error and it's getting really frustrating!

所以有人知道还有什么我可以尝试修复这个错误?

So does anybody know what else I can try to fix this error?

推荐答案

这不是IIS的问题,而是WCF的问题。默认情况下,WCF将消息限制为65KB,以避免使用大消息进行拒绝服务攻击。此外,如果您不使用MTOM,它会将byte []发送到base64编码的字符串(大小增加33%)=> 48KB * 1,33 = 64KB

That is not problem of IIS but the problem of WCF. WCF by default limits messages to 65KB to avoid denial of service attack with large messages. Also if you don't use MTOM it sends byte[] to base64 encoded string (33% increase in size) => 48KB * 1,33 = 64KB

要解决此问题,您必须重新配置您的服务以接受更大的消息。此问题之前触发了400 Bad Request错误,但在较新版本中,WCF开始使用413,这是此类错误的正确状态代码。

To solve this issue you must reconfigure your service to accept larger messages. This issue previously fired 400 Bad Request error but in newer version WCF started to use 413 which is correct status code for this type of error.

您需要设置<$ c绑定中的$ c> maxReceivedMessageSize 。您还可以设置 readerQuotas

You need to set maxReceivedMessageSize in your binding. You can also need to set readerQuotas.

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding maxReceivedMessageSize="10485760">
        <readerQuotas ... />
      </binding>
    </basicHttpBinding>
  </bindings>  
</system.serviceModel>

这篇关于(413)请求实体太大|应将UploadReadAheadSize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆