【问题标题】:413 Request Entity Too Large WCF413 请求实体太大 WCF
【发布时间】:2016-09-08 09:05:08
【问题描述】:

我已经看到有关此主题的其他帖子,并认为我已经尝试了所有方法,但在尝试保存更大的文件时似乎无法解决此错误。我已经在配置文件的两个部分中提高了 maxReceivedMessageSize 和所有其他与大小相关的配置,并且还通过 IIS 管理器提高了 uploadReadAheadSize。我看不出我可能会丢失什么,所以我会发布我的配置文件,希望有人能够发现错误。

服务配置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
      <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c5rge93gerg9" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" maxRequestLength="2147483647" />
  </system.web>
  <system.serviceModel>
      <client>
         <endpoint address="/" binding="basicHttpBinding" bindingConfiguration="MyHttpBinding" contract="*" name="Default" />
      </client>
    <bindings>
        <basicHttpBinding>
            <binding name="MyHttpBinding" hostNameComparisonMode="Exact" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            </binding>
        </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="2147483647" />
        </requestFiltering>
    </security>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="true" />
  </system.webServer>
  <connectionStrings>
  </connectionStrings>
  <entityFramework>
      <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>

客户端配置的相关部分:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="MyHttpBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
                <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            </binding>
        </basicHttpBinding>
    </bindings>
<client>
  <endpoint address="http://Service1.svc" binding="basicHttpBinding"
    bindingConfiguration="MyHttpBinding" contract="ServiceReference1.IService1"
    name="MyHttpBinding" />
</client>

【问题讨论】:

  • 文件有多大?
  • @AmitKumarGhosh 只有大约 2MB

标签: .net wcf


【解决方案1】:

我在您的服务配置中没有看到 &lt;services&gt; 部分,因此即使您定义了具有较大值的绑定,它也没有被使用,因为它没有设置为默认绑定,也没有明确分配给端点。相反,您将获得一个具有默认配额和限制的 basicHttpBinding

在您的情况下,最简单的解决方法可能是修复服务的配置文件并删除 &lt;client&gt; 部分并添加 &lt;services&gt; 部分,如下所示:

<services>
  <service name="MyServiceName">
    <endpoint address="/" 
              binding="basicHttpBinding"
              bindingConfiguration="MyHttpBinding" 
              contract="*" 
              name="Default" />
  </service>
</services>

这会将“MyHttpBinding”配置分配给您的端点。

请注意,您还可以通过省略 name 属性使“MyHttpBinding”成为所有 basicHttpBinding 端点的默认配置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-05
    • 2011-02-22
    • 1970-01-01
    • 2016-11-14
    • 2014-12-30
    • 2014-12-23
    • 1970-01-01
    相关资源
    最近更新 更多