(413) 请求实体太大 |上传预读大小 [英] (413) Request Entity Too Large | uploadReadAheadSize

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

问题描述

我用 .NET 4.0 编写了一个 WCF 服务,它托管在我的 Windows 7 x64 Ultimate 系统和 IIS 7.5 上.其中一种服务方法有一个对象"作为参数,我正在尝试发送一个包含图片的字节 [].只要这张图片的文件大小小于大约.48KB,一切顺利.但是,如果我尝试上传更大的图片,WCF 服务会返回错误:(413) Request Entity Too Large.所以当然我花了 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//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.

您需要在绑定中设置 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) 请求实体太大 |上传预读大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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