2016-05-12 172 views
0

我已經看到關於此主題的其他帖子,並認爲我已經嘗試了一切,似乎無法解決此錯誤時,試圖保存一個較大的文件。我在配置文件的兩個部分都碰到了maxReceivedMessageSize和所有其他大小相關的配置,並且還通過IIS管理器調高了uploadReadAheadSize。我看不到我可能會丟失什麼,所以我會發布我的配置文件,希望有人能夠發現錯誤。413請求實體太大WCF

服務配置:

<?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> 

+0

文件有多大? –

+0

@AmitKumarGhosh只有大約2MB – JSchins

回答

0

我沒有看到你的服務配置一個<services>部分,所以即使你定義了一個具有較大值的綁定,它沒有被使用,因爲它沒有被設置爲默認綁定,也沒有明確分配給端點。相反,你得到一個basicHttpBinding與默認配額和限制。

在你的情況,最簡單的解決方法是可能修復服務的配置文件並刪除<client>部分,並添加一個<services>部分,像這樣:

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

這將「MyHttpBinding」配置分配給你的端點。

請注意,您還可以通過省略name屬性使「MyHttpBinding」成爲所有basicHttpBinding端點的默認配置。