wcf流式传输大文件内存错误

时间:2013-04-02 09:02:08

标签: c# wcf file streaming

我有一个wcf服务,我用它来传输文件。即时通讯使用basicHttpBinding流模式。我在web.config和app.config(客户端)中正确配置了一些值(我猜)但是它没有按照我的预期工作。它可以发送和接收高达1,610,611,200字节,接近1.5 GB。每次我将大于此大小的文件上传到服务器时,在此限制下,我的服务方法会抛出“读取流时抛出异常”。例外。当我尝试下载大于这个大小的文件时,它会抛出“类型'System.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>

btw我在服务器上有8GB的ram,在客户端也有8gb的ram。因为它是流传输transferMode它不一定使用rams但我现在想,如果它是一个内存问题:( 任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

上周我遇到了同样的问题。我想我找到了解决方案。我更改了maxReceivedMessageSize =&#34; 4294967295&#34; (接近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文件。

答案 1 :(得分:0)

感谢@JJ_CoderHir。

我遇到了同样的问题。使用下面的代码可以解决。据我的理解,由于正确的默认值“ requestLengthDiskThreshold”,我遇到了System.OutOfMemory问题。因此,我现在进行了更改,它可以按我的期望运行。

<system.web>
    <httpRuntime maxRequestLength="2147483647" requestLengthDiskThreshold="2097151" executionTimeout="240"/>
</system.web>
<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="2147483648" />
        </requestFiltering>
    </security>
</system.webServer>
相关问题