【发布时间】:2014-09-15 19:01:44
【问题描述】:
当我通过 WCF 服务上传文件时,我收到异常“远程服务器返回错误:(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 上传大文件?
谢谢。
【问题讨论】:
标签: c# asp.net wcf iis file-upload