413请求实体太大WCF

时间:2016-05-12 13:30:15

标签: .net wcf

我已经看过关于此主题的其他帖子,并认为我已尝试过所有内容,并且在尝试保存较大的文件时似乎无法解决此错误。我已经在配置文件的两个部分中增加了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>

1 个答案:

答案 0 :(得分:0)

我在服务配置中没有看到<services>部分,所以即使你已经定义了一个具有较大值的绑定,它也没有被使用,因为它没有被设置为默认绑定,也没有被明确赋值到端点。相反,您将获得具有默认配额和限制的basicHttpBinding

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

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

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

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