The remote server returned an error: (413) Request Entity Too Large (TRIED EVERY SOLUTION ON EARTH)

The remote server returned an error: (413) Request Entity Too Large (TRIED EVERY SOLUTION ON EARTH)

我正在将图像从 MVC 项目上传到 WCF 项目。图像文件小于或等于 50 KB 没问题,但大于 50 KB 的问题。

我已经将 system.webServer > IIS 的 serverRuntime 的 UploadReadAheadSize 的大小增加到 52428800。没有用。

尝试使用 WCF web.config 文件的所有最大长度的绑定配置。没用。

尝试在 WCF web.config 文件中使用 MOTM 编码类型。没用。

下面是我的配置文件。

:::WCF Web.Config:::

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="AppServerURL" value="AppServer://192.168.12.44:5162/WService_618"/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.6" />
    <httpRuntime targetFramework="4.6"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IServiceProWCFService" sendTimeout="00:25:00"
          allowCookies="true" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647" transferMode="StreamedRequest" messageEncoding="Mtom">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>    
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

:::MVC Web.Config:::

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <sectionGroup name="businessObjects">
      <sectionGroup name="crystalReports">
        <section name="rptBuildProvider" type="CrystalDecisions.Shared.RptBuildProviderHandler, CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, Custom=null" />
        <section name="crystalReportViewer" type="System.Configuration.NameValueSectionHandler" />
      </sectionGroup>
    </sectionGroup>
  </configSections>
  <businessObjects>
    <crystalReports>
      <rptBuildProvider>
        <add embedRptInResource="true" />
      </rptBuildProvider>
      <crystalReportViewer>
        <add key="ResourceUri" value="/crystalreportviewers13" />
      </crystalReportViewer>
    </crystalReports>
  </businessObjects>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="CrystalImageCleaner-AutoStart" value="true" />
    <add key="CrystalImageCleaner-Sleep" value="60000" />
    <add key="CrystalImageCleaner-Age" value="120000" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
    <pages>
      <namespaces>
        <add namespace="Kendo.Mvc.UI" />
      </namespaces>
    </pages>
    <httpHandlers>
      <add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web,Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
    </httpHandlers>
    <sessionState timeout="180"></sessionState>
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IServiceProWCFService" maxBufferSize="2147483647"
          maxReceivedMessageSize="2147483647" receiveTimeout="00:30:00" sendTimeout="00:30:00" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:22918/ServiceProWCFService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServiceProWCFService"
        contract="ServiceProWCFService.IServiceProWCFService" name="BasicHttpBinding_IServiceProWCFService" />
    </client>
  </system.serviceModel>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode"/>      
    </handlers>
  </system.webServer>
</configuration>

我的问题解决了。我刚刚更改了 WCF 的 web.config。就是这样

    <bindings>
      <basicHttpBinding>
        <binding maxReceivedMessageSize="2147483647"
          maxBufferSize="2147483647"
          maxBufferPoolSize="2147483647" sendTimeout="00:25:00">
          <readerQuotas maxDepth="32"
          maxArrayLength="2147483647"
          maxStringContentLength="2147483647"/>
        </binding>
      </basicHttpBinding>
    </bindings>