當我通過WCF服務上傳文件時,收到異常「遠程服務器返回錯誤:(413)請求實體太大」文件上傳,遠程服務器返回錯誤:(413)請求實體太大
關於這個例外有很多問題和答案。但是,他們都沒有解決我的問題。
我正在使用Windows Web Server 2008 R2,IIS 7.5。我的客戶端和WCF應用程序託管在IIS中。我正在使用頻道來調用WCF服務。
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配置文件,如下所示:
<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>
而且,我添加了客戶端的web.config文件進行如下操作:
<httpRuntime maxRequestLength="2097151" />
<serverRuntime uploadReadAheadSize="2147483647" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
我改變了C:\ Windows \ System32下\ inetsrv \ config \ applicationHost.config,
<location path="My Site Path" overrideMode="Allow">
<system.webServer>
<httpLogging dontLog="true" />
<serverRuntime uploadReadAheadSize="2147483647" />
</system.webServer>
</location>
但是,他們都沒有解決我的問題。 Windows Server 2012沒有問題。可能與Windows Server 2008有關。如何在Windows Server 2008中使用WCF上傳大文件?
謝謝。
我注意到你談到更新客戶端的web.config中,客戶端程序Web.Config發出請求,而服務器是請求過濾發生,所以更改客戶端的web.config的請求限制將不起作用。 –
另外,我會考慮使用WCF流,它可以防止文件存儲在RAM中。我使用它來傳輸大文件而沒有這些問題。 –
我更改了客戶端web.config和WCF應用程序web.config。但是沒有效果。 – selami