远程服务器返回错误:(413)请求实体太大

问题描述:

我知道这是一个多余的问题,我在上传大于100 KB的文件时出现错误。远程服务器返回错误:(413)请求实体太大

The remote server returned an error: (413) Request Entity Too Large.

我将内容发布到WCF服务(64位环境)。我知道这应该已经通过管理maxReceivedMessageSize和相关行为来解决,但不幸的是它没有。

下面是我的配置: -

客户

 <binding allowCookies="false" bypassProxyOnLocal="false" closeTimeout="00:01:00" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" name="BasicHttpBinding_ICandidateManagementService" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:11:00" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true"> 
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" 
      maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> 
      <security mode="None"> 
      <transport clientCredentialType="None" proxyCredentialType="None" realm=""/> 
      <message algorithmSuite="Default" clientCredentialType="UserName"/> 
      </security> 
     </binding> 

<behavior name="CandidateBehavior"> 
      <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
     </behavior> 

<endpoint address="http://localhost:62368/CandidateManagementService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICandidateManagementService" contract="MMJ.ServiceContracts.ServiceContract.ICandidateManagementService" name="BasicHttpBinding_ICandidateManagementService" behaviorConfiguration="CandidateBehavior" /> 

服务

<services> 
     <service name="BasicHttpBinding_ICandidateManagementService" behaviorConfiguration="CandidateBehavior"> 
     <endpoint contract="MMJ.ServiceContracts.ServiceContract.ICandidateManagementService" binding="basicHttpBinding" address="" bindingConfiguration="BasicHttpBinding_ICandidateManagementService"/> 
     </service> 

我所看到的一切可能提供与斜面仍然解决这个问题。也尝试过使用下面的配置,但仍然没有变化...

<serverRuntime uploadReadAheadSize="500000000" maxRequestEntityAllowed="500000000"/> 

请帮忙!

服务绑定配置(其作为客户端相同)

<binding allowCookies="false" bypassProxyOnLocal="false" closeTimeout="00:01:00" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" name="BasicHttpBinding_ICandidateManagementService" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:11:00" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> 
      <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="32" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647"/> 
      <security mode="None"> 
      <transport clientCredentialType="None" proxyCredentialType="None" realm=""/> 
      <message algorithmSuite="Default" clientCredentialType="UserName"/> 
      </security> 
     </binding> 

为了让下面更深入的了解是小提琴手发现: -

Request Count: 1 Bytes Sent: 85,719 (headers:697; body:85,022) Bytes Received: 10,129 (headers:254; body:9,875)

+0

我以为你还需要在IIS中设置一些东西,但不知道肯定。 – 2013-03-11 13:40:56

+0

我不这么认为,如果你遇到任何问题,请告诉我。 – Wali 2013-03-11 16:14:45

+0

我在Chrome上检索到相同的错误。当我切换到Firefox时,所有问题都消失了。 – 2016-12-16 19:13:00

最后我的问题所困扰了很多之后得到解决。 我的服务配置有一个缺陷,它没有给我任何运行时或编译时错误,因为它甚至没有识别配置。

我的服务配置为: -

<services> 
     <service name="BasicHttpBinding_ICandidateManagementService" behaviorConfiguration="CandidateBehavior"> 
     <endpoint contract="MMJ.ServiceContracts.ServiceContract.ICandidateManagementService" binding="basicHttpBinding" address="" bindingConfiguration="BasicHttpBinding_ICandidateManagementService"/> 
     </service> 

我有“名称”属性,它不是我服务的全名,因此我所用甚至没有考虑,因此正在采取默认的65KB配置为maxReceivedMessageSize。

我已更新它,它的工作就像一个魅力。

<services> 
    <service name="MMJ.Services.CandidateManagementService"> 
    <endpoint contract="MMJ.ServiceContracts.ServiceContract.ICandidateManagementService" binding="basicHttpBinding" address="" bindingConfiguration="BasicHttpBinding_ICandidateManagementService"/> 
    </service> 

另外,看看这个post为更多的参考。我知道这是一个愚蠢的错误,并且感谢大家努力修复。

+0

您的问题对我有帮助。我有同样的问题,但只是使用'maxReceivedMessageSize =“2000000”'解决。 – 2014-01-20 13:04:38

你的数据发布到服务器,因此更新客户端设置将无济于事。客户端不是接收大消息的服务器。

+0

我同意...我已经更新了服务器配置。它仍然没有产生任何结果。 – Wali 2013-03-11 16:14:01

+0

你可以发布配置的“BasicHttpBinding_ICandidateManagementService”部分吗? – Rich 2013-03-11 17:07:04

+0

它已经发布在我的问题...我再次张贴... – Wali 2013-03-11 17:29:27

看你的客户端点:

不应该bindingConfiguration是

bindingConfiguration="BasicHttpBinding_ICandidateManagementService" 

而不是

bindingConfiguration="BasicHttpBinding_IAdminService" 
+0

这只是一个错误的错误,我正在使用正确的配置。 – Wali 2013-03-12 03:57:05

+0

您是为您的传输模式进行流式传输还是缓存(是您的参数/响应流类型)?根据你的配置,你正在做缓冲服务,但在客户端流式传输。我认为他们在每一端都必须是相同的,否则它将如何知道如何分块呢?你有/你可以试着让它们相同,并再次尝试一下,看看它是否有效? – 2013-03-12 15:09:14

+0

我检查过了,我在服务器和客户端都使用了缓冲区。由于在我的实现中没有流式传输的概念。 – Wali 2013-03-12 18:01:47