上传文件错误 - 远程服务器返回意外响应:(413)请求实体太大 [英] upload file error - The remote server returned an unexpected response: (413) Request Entity Too Large

查看:96
本文介绍了上传文件错误 - 远程服务器返回意外响应:(413)请求实体太大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器端制作WCF服务以上传文件并插入数据库。但是,我发现问题..当我从桌面应用程序上传文件(调用该WCF服务)时,它说远程服务器返回了意外的响应: (413)请求实体太大..我找到了来自互联网的解决方案,他们说要增加uploadreadaheadsize,请求过滤,maxReceivedMessageSize,maxBufferSize,maxbufferpoolsize等的值(在app.config和web.config中)..我试过所有这些,但它是一样的..



这里是我的web.config

< serverRuntime uploadReadAheadSize = 2147483647/> 
< security>
< requestFiltering>
< requestLimits maxAllowedContentLength =2147483647/>
< / requestFiltering>
< / security>
< /system.webServer>
< system.serviceModel>
< bindings>
< basicHttpBinding>

< binding name =basicHttpallowCookies =true
maxReceivedMessageSize =2147483647
maxBufferSize =2147483647
maxBufferPoolSize =2147483647
transferMode =Streamed
messageEncoding =Text
textEncoding =utf-8
bypassProxyOnLocal =false
useDefaultWebProxy =true>
< readerQuotas maxDepth =2147483647
maxArrayLength =2147483647
maxStringContentLength =2147483647
maxBytesPerRead =2147483647
maxNameTableCharCount =2147483647/> ;
< / binding>
< / basicHttpBinding>
< / bindings>
< behavior>
< serviceBehaviors>
< behavior name =>
< dataContractSerializer maxItemsInObjectGraph =2147483647/>
< serviceMetadata httpGetEnabled =true/>
< serviceDebug includeExceptionDetailInFaults =true/>
< / behavior>
< / serviceBehaviors>
< endpointBehaviors>
< behavior>
< dataContractSerializer maxItemsInObjectGraph =2147483647/>
< / behavior>
< / endpointBehaviors>
< / behavior>





这是我的app.config

<绑定> 
< basicHttpBinding>
< binding name =BasicHttpBinding_IServiceallowCookies =false
bypassProxyOnLocal =falsemaxBufferPoolSize =2147483647maxReceivedMessageSize =2147483647maxBufferSize =2147483647
useDefaultWebProxy =true >
< readerQuotas maxDepth =2147483647
maxArrayLength =2147483647
maxStringContentLength =2147483647
maxBytesPerRead =2147483647
maxNameTableCharCount =2147483647/> ;
< security mode =None/>
< / binding>
< / basicHttpBinding>
< / bindings>
< behavior>
< serviceBehaviors>
< behavior name =>
< dataContractSerializer maxItemsInObjectGraph =2147483647/>
< serviceMetadata httpGetEnabled =true/>
< serviceDebug includeExceptionDetailInFaults =true/>
< / behavior>
< / serviceBehaviors>

< endpointBehaviors>
< behavior>
< dataContractSerializer maxItemsInObjectGraph =2147483647/>
< / behavior>
< / endpointBehaviors>
< / behavior>

< client>
< endpoint address =http:// localhost:3724 / Service.svcbinding =basicHttpBinding
bindingConfiguration =BasicHttpBinding_IServicecontract =ServiceReference1.IService/>
< / client>





你能给我解决方案吗?我非常需要它..谢谢

解决方案

如果问题不在您的应用程序上,而是在服务器应用程序上,并且您尝试通过以下方式访问webApplication WCF,您需要在服务器应用程序上设置maxRequestLength,就像在app.config上执行的操作一样。

http://msdn.microsoft.com/pt-br/library/e1f13641(v=vs .85).aspx



如果异常抛出你的WCF应用程序,你需要在app.config上设置maxReceivedMessageSize。



 WCF  默认限制消息  64KB  避免DOS攻击 大邮件。  默认,它将byte [] 发送为 base64编码的字符串它增加了 消息(增加了33% in  size)。   如果上传的 file  size < span class =code-keyword> 〜大于48KB 然后它会引发上述错误。 (48KB *  1  33  = ~64KB)(注意,你可以使用 MTOM  - 消息传输优化机械化 优化消息)

通过修改 maxReceivedMessageSize in Web.config 文件 接受大邮件,你可以解决这个问题。





(413)请求实体太大 [ ^ ]



祝你好运,



Leonardo Meter


i make WCF service on server side to upload file and insert to database.but,i find a problem..when i upload file from desktop app (call that WCF Service),it's say The remote server returned an unexpected response: (413) Request Entity Too Large..i have found the solution from internet and they say to increase values of uploadreadaheadsize, request filtering, maxReceivedMessageSize, maxBufferSize, maxbufferpoolsize, etc (in app.config and web.config)..i have tried all of them,but it's same..

here is my web.config

<serverRuntime uploadReadAheadSize="2147483647" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>
<system.serviceModel>
<bindings>
<basicHttpBinding>
 
<binding name="basicHttp" allowCookies="true"
maxReceivedMessageSize="2147483647" 
maxBufferSize="2147483647"
maxBufferPoolSize="2147483647"
transferMode="Streamed"
messageEncoding="Text"
textEncoding="utf-8"
bypassProxyOnLocal="false"
useDefaultWebProxy="true" >
<readerQuotas maxDepth="2147483647" 
maxArrayLength="2147483647"
maxStringContentLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>



here is my app.config

<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" allowCookies="false"
bypassProxyOnLocal="false" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
useDefaultWebProxy="true">
<readerQuotas maxDepth="2147483647"
maxArrayLength="2147483647"
maxStringContentLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
 
<endpointBehaviors>
<behavior>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
</behaviors>
 
<client>
<endpoint address="http://localhost:3724/Service.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService" />
</client>



can you give me solution? i'm very need it..thanks

解决方案

if the problem isn't on your application but on server application and you you're trying to access an webApplication via WCF, you need to set the maxRequestLength on server application like the same action made on app.config.
http://msdn.microsoft.com/pt-br/library/e1f13641(v=vs.85).aspx

If the exception throws on you WCF application, you need to set the maxReceivedMessageSize on app.config.

WCF by default limits messages to 64KB to avoid DOS attack with large message. By default, it sends byte[] as base64 encoded string and it increases the size of the message (33% increase in size). There for if the uploaded file size is ~larger than 48KB then it raises the above error. (48KB * 1.33 = ~64KB) (NB. you can use MTOM – Message Transmission Optimization Mechanize to optimize the message)

By modifying the "maxReceivedMessageSize" in the Web.config file to accept large messages, you can solve this issue.



(413) Request Entity Too Large[^]

Best regards,

Leonardo Metre


这篇关于上传文件错误 - 远程服务器返回意外响应:(413)请求实体太大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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