【问题标题】:The remote server returned an error: (413) Request Entity Too Large远程服务器返回错误:(413) Request Entity Too Large
【发布时间】:2013-03-11 13:37:46
【问题描述】:

我知道这是一个多余的问题,我在上传超过 100 KB 的文件时遇到了错误。

远程服务器返回错误:(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>

以下是提琴手的发现:-

请求计数:1 发送字节数:85,719(标头:697;正文:85,022) 收到的字节数:10,129(标头:254;正文:9,875)

【问题讨论】:

  • 我以为你还需要在 IIS 中设置一些东西,但不确定。
  • 我不这么认为,如果你遇到了请告诉我。
  • 我在 Chrome 上检索到了同样的错误。当我切换到 Firefox 时,所有问题都消失了。

标签: wcf


【解决方案1】:

经过一番苦苦挣扎,我的问题终于解决了。 我的服务配置存在缺陷,它没有给我任何运行时或编译时错误,因为它甚至无法识别配置。

我的服务配置是:-

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

我的“名称”属性不是我的服务的完全限定名称,因此甚至没有考虑我使用的配置,因此默认为 maxReceivedMessageSize 65KB。

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

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

另外,请查看post 以获取更多参考。我知道这是一个愚蠢的错误,感谢大家努力改正。

【讨论】:

  • 你的问题对我很有帮助。我遇到了同样的问题,但仅使用 maxReceivedMessageSize="2000000" 就解决了。
【解决方案2】:

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

【讨论】:

  • 我同意...我已经更新了服务器配置。它仍然没有产生任何结果。
  • 你能发布配置的“BasicHttpBinding_ICandidateManagementService”部分吗?
  • 感谢 Rich 的帮助...我最终解决了这个问题。
【解决方案3】:

查看您的客户端端点:

bindingConfiguration不应该是

bindingConfiguration="BasicHttpBinding_ICandidateManagementService"

代替

bindingConfiguration="BasicHttpBinding_IAdminService"

【讨论】:

  • 这只是问题中的拼写错误,我使用的是正确的配置。
  • 您是流式传输还是缓冲传输模式(您的参数/响应流类型)?根据您的配置,您正在对服务进行缓冲,但在客户端进行流式传输。我认为它们在每一端都必须相同,否则它将如何知道如何相应地对其进行分块?您/您是否可以尝试使它们相同并再试一次,看看是否可行?
  • 我检查过了,在服务器和客户端都使用缓冲。因为在我的实现中没有流的概念。
猜你喜欢
  • 2012-10-05
  • 1970-01-01
  • 1970-01-01
  • 2014-09-15
  • 2016-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多