You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

遭遇413 Request Entity Too Large错误,已尝试多种方案仍未解决

排查WCF请求实体过大(413错误)问题

问题说明

收到错误提示:"The remote server returned an unexpected response: (413) Request Entity Too Large.",已查阅Stack Overflow相关方案并尝试调整,仍未定位到web.config中的问题,现将配置和已尝试方案整理如下。

当前web.config配置

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>

    <system.web>
      <compilation targetFramework="4.6" debug="true">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
    <caching>
      <outputCacheSettings>
        <outputCacheProfiles>
          <add name="DefaultCache" duration="60" varyByParam="none" />
        </outputCacheProfiles>
      </outputCacheSettings>
    </caching>
    <authentication mode="Windows" />
    <pages controlRenderingCompatibilityVersion="4.0" />
  </system.web>

  <system.webServer>
      <security>
          <requestFiltering>
              <requestLimits maxAllowedContentLength="3521478366" />
          </requestFiltering>
      </security>
  </system.webServer>

  <system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
    <bindings>

        <basicHttpBinding>
            <binding name="BasicHttpEndpointBinding" allowCookies="true"
                     maxReceivedMessageSize="2147483647"
                     maxBufferSize="2147483647"
                     maxBufferPoolSize="2147483647">
                <readerQuotas maxDepth="32"
                              maxArrayLength="2147483647"
                              maxStringContentLength="2147483647"/>
            </binding>
        </basicHttpBinding>

    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 避免泄露元数据信息,部署前请将以下值设为false并移除上方元数据端点 -->
          <serviceMetadata httpGetEnabled="false" />
          <!-- 为调试目的在错误中接收异常详情,部署前请设为false以避免泄露异常信息 -->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="restBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>

        <service name="TruckService.TruckService">
        <endpoint 
            binding="basicHttpBinding" 
            bindingConfiguration="BasicHttpEndpointBinding" 
            contract="TruckService.ITruckService">
            <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>

      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
      <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="false" showFlags="Date, Time, Size, Extension" />
  </system.webServer>
  <connectionStrings>

        <!-- 出于安全已移除 -->

  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

已尝试的方案

  • 调整WCF调用端的MaxReceivedMessageSize参数
  • 针对“传入消息的最大消息大小配额(65536)已超出”问题调整配置

排查方向

  • 合并重复的<system.webServer>节点:配置中存在两个<system.webServer>节点,IIS读取时可能仅识别第一个,导致第二个节点的设置失效。需合并为单个节点:
<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="3521478366" />
        </requestFiltering>
    </security>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="false" showFlags="Date, Time, Size, Extension" />
</system.webServer>
  • 检查端点绑定配置:确认所有WCF服务端点都正确关联了自定义的BasicHttpEndpointBinding,未指定绑定配置的端点会使用默认小配额,可能引发错误。
  • 同步客户端配置:若错误在客户端调用时返回,客户端配置需同步设置相同的maxReceivedMessageSize、maxBufferSize等参数,不能仅修改服务端。
  • 核对IIS站点级请求限制:除web.config外,需在IIS管理器对应站点的“请求筛选”中,确认“最大允许内容长度”与web.config设置一致,避免站点级配置覆盖局部配置。

内容的提问来源于stack exchange,提问作者SomeoneSpecial

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.22 18:18:27