When I upload a file via WCF services, I received the exception, "The remote server returned an error: (413) Request Entity Too Large"
There are a lot of questions and answers about this exception. But, none of them is solved my problem.
I'm using Windows Web Server 2008 R2, IIS 7.5. My client and WCF applications are hosted in IIS. I'm using channel to call WCF service.
var binding = new BasicHttpBinding();
binding.MaxReceivedMessageSize = Int32.MaxValue;
binding.MaxBufferPoolSize = Int32.MaxValue;
binding.MaxBufferSize = Int32.MaxValue;
binding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
binding.ReaderQuotas.MaxBytesPerRead = Int32.MaxValue;
binding.ReaderQuotas.MaxDepth = Int32.MaxValue;
binding.ReaderQuotas.MaxNameTableCharCount = Int32.MaxValue;
var address = new EndpointAddress("WCF Service URL");
return ChannelFactory<IFileService>.CreateChannel(binding, address);
WCF configuration file like the following:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="behavior1">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="MyProject.WCF.FileService" behaviorConfiguration="behavior1">
<endpoint binding="basicHttpBinding" bindingName="binding1" contract="MyProject.WCF.Contracts.Service.IFileService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="binding1" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Also, I add the client web.config file the following configurations:
<httpRuntime maxRequestLength="2097151" />
<serverRuntime uploadReadAheadSize="2147483647" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
I changed C:WindowsSystem32inetsrvconfigapplicationHost.config,
<location path="My Site Path" overrideMode="Allow">
<system.webServer>
<httpLogging dontLog="true" />
<serverRuntime uploadReadAheadSize="2147483647" />
</system.webServer>
</location>
But, none of them is solved my problem. There is no problem with Windows Server 2012. Probably, the problem is related to Windows Server 2008. How can upload large files with WCF in Windows Server 2008?
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…