我有一个wcf服务,我使用它传输文件。我使用basicHttpBinding流模式。我在两个web中配置了一些值。config和app.config(客户端)正确(我猜),但它不像我期望的那样工作。它可以发送和接收多达1,610,611,200字节,接近1.5 gb。每次我上传一个大于这个大小的文件到服务器,在这个限制下,我的服务方法抛出"读取流时抛出异常"异常。当我尝试下载一个大于这个大小的文件时,它会抛出"类型异常"系统。OutOfMemoryException'被抛出。"异常。以下是我的配置文件相关部分。希望有人能给我指点一下,解决这个问题。
<basicHttpBinding> (web config)
<binding name="StreamServiceHttpBinding" receiveTimeout="01:00:10" sendTimeout="03:00:30" maxBufferPoolSize="2147483647"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
transferMode="Streamed">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
<basicHttpBinding> (app config)
<binding name="BasicHttpBinding_IStreamService" receiveTimeout="01:00:10"
sendTimeout="03:00:30" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" transferMode="Streamed">
<readerQuotas maxDepth="128" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
顺便说一句,我在服务器上有8gb的ram,在客户端也有8gb的ram。因为它是流式传输模式,它不一定使用公羊,但我认为现在如果它是一个内存问题:(
我上周也遇到了同样的问题。我想我找到解决办法了。我改变了maxReceivedMessageSize="4294967295"(将近4GB),并增加了超时时间。
app.config
<bindings>
<basicHttpBinding>
<binding name="GShare.Sharer" receiveTimeout="00:40:00" sendTimeout="00:40:00" maxReceivedMessageSize="4294967295" maxBufferSize="2147483647" maxBufferPoolSize="4294967295" transferMode="StreamedRequest">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None">
</security>
</binding>
</basicHttpBinding>
</bindings>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="4294967295"/>
</requestFiltering>
</security>
</system.webServer>
客户机web . config <binding name="BasicHttpBinding_ISharer" closeTimeout="24:01:00" openTimeout="24:01:00" receiveTimeout="24:10:00" sendTimeout="24:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="4294967295" maxBufferSize="2147483647" maxReceivedMessageSize="4294967295" textEncoding="utf-8" transferMode="Streamed" useDefaultWebProxy="true" messageEncoding="Text">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
之后,我成功上传了1.89GB的文件。
感谢@JJ_CoderHir.
我也遇到了同样的问题。使用下面的代码来解决这个问题。根据我的理解,由于"requestLengthDiskThreshold"的默认值,我正在获得系统。OutOfMemory问题。所以我改变了它,现在它按照我的期望工作了。
<system.web>
<httpRuntime maxRequestLength="2147483647" requestLengthDiskThreshold="2097151" executionTimeout="240"/>
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
</system.webServer>