C# wcf流式处理内存不足的大文件错误

C# wcf流式处理内存不足的大文件错误,c#,wcf,file,streaming,C#,Wcf,File,Streaming,我有一个wcf服务,我使用它来传输文件。im使用basicHttpBinding流模式打开。我在web.config和app.config(客户端)中都正确地配置了一些值(我猜),但它并没有像我预期的那样工作。它可以发送和接收高达1610611200字节(接近1.5 gb)的数据。每次我将大于此大小的文件上载到服务器时,在此限制下,我的服务方法都会抛出“读取流时引发异常”。异常。当我试图下载一个大于这个大小的文件时,它抛出“类型为'System.OutOfMemoryException'的异常。

我有一个wcf服务,我使用它来传输文件。im使用basicHttpBinding流模式打开。我在web.config和app.config(客户端)中都正确地配置了一些值(我猜),但它并没有像我预期的那样工作。它可以发送和接收高达1610611200字节(接近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>
(web配置)
(应用程序配置)
顺便说一句,我在服务器上有8gb的ram,在客户端也有8gb的ram。因为它是流传输模式,所以不一定使用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”正确,我得到了System.OutOfMemory问题。因此我现在已经更改了它,它按照我的预期工作

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


你应该将它流成更小的块。这是一篇很好的文章,很难说我在这篇文章中找不到任何有益的信息:/非常感谢,但是我已经学到了很多好东西。读到这里,你可以考虑增加HythPunTimeMax请求长度。你最终做了什么?你是得到了
系统。OutOfMemoryException
异常,还是你得到了
maxReceivedMessageSize被超过了
异常?有趣的是,直到超时结束,我才得到一个错误,当它发生时,客户端只是在查看正常页面-一旦停止加载,就没有响应。当我查看我的服务器时,wcf上传了1.5gb,但没有更多。它只是停止运行代码,比如停止线程之类的。