使用WCF发送大数据而不进行流式传输

Kin*_*han 3 c# wcf

我们正在尝试构建一个可以从kb~gb大小发送/接收大型数据文件的Web服务.

我知道我们应该使用流式传输来预先形成,这样就不会破坏内存.

但问题是我们不想改变我们的设计,或者更像是,现在我们将尝试看看当我们在带有WCF的byte []缓冲传输模式中传输大文件时只会说150mb文件时会发生什么.(我知道是goign将整个文件缓冲到内存中...如果我们传输gb大小的文件会崩溃/异常......)

但即使这样,他们也想看看会发生什么,所以我在WCF配置中有我的wsHttpBinding:

  <system.web>
    <compilation debug="true"/>
      <httpRuntime maxRequestLength="524288"/>
  </system.web>
....

  <wsHttpBinding>
    <binding name="wsHttpBinding1" closeTimeout="00:10:00" openTimeout="00:10:00"
          receiveTimeout="00:30:00" sendTimeout="00:30:00" bypassProxyOnLocal="false"
          hostNameComparisonMode="StrongWildcard"                  
                                    maxBufferPoolSize="52428800" maxReceivedMessageSize="65536000"
          messageEncoding="Mtom" useDefaultWebProxy="true">
      <security mode="None" />
    </binding>
  </wsHttpBinding>
Run Code Online (Sandbox Code Playgroud)

然后我的客户端应用配置:

          <wsHttpBinding>
                <binding name="WSHttpBinding_IPrintService" closeTimeout="00:01:00"
                      openTimeout="00:01:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
                      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                                    maxBufferPoolSize="52428800" maxReceivedMessageSize="65536000"
                      messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true"                           
                      allowCookies="false">
                      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                      <reliableSession ordered="true" inactivityTimeout="00:10:00"
                            enabled="false" />
                  <security mode="None"/>
                </binding>
          </wsHttpBinding>
Run Code Online (Sandbox Code Playgroud)

当我传输小数据时它工作正常,但当我尝试传输150mb文件时,它给了我例外:

InnerException = {"无法将数据写入传输连接:无法执行对套接字的操作,因为系统缺少足够的缓冲区空间或因为队列已满."}

我试图增加maxReceivedMessage等,但它仍然有同样的问题....

======

编辑:我试图将所有可能的值增加到... 2147483647 ....我可以成功发送一个30mb文件..但仍然不是150mb ....而且我也尝试使用这个CustomBinding:

<customBinding>         
        <binding name="LargeCustomBinding" 
                 receiveTimeout="01:00:00"  
                 openTimeout="01:00:00"  
                 closeTimeout="01:00:00"  
                 sendTimeout="01:00:00"> 
          <binaryMessageEncoding  
            maxReadPoolSize="2147483647"  
            maxSessionSize="2147483647"  
            maxWritePoolSize="2147483647"> 
            <readerQuotas  
              maxArrayLength="2147483647"  
              maxDepth="2147483647"  
              maxBytesPerRead="2147483647"  
              maxNameTableCharCount="2147483647"  
              maxStringContentLength="2147483647" /> 
          </binaryMessageEncoding> 
          <httpTransport  
            maxBufferSize="2147483647"  
            maxReceivedMessageSize="2147483647"  
            maxBufferPoolSize="2147483647"/> 
        </binding> 
      </customBinding>
Run Code Online (Sandbox Code Playgroud)

但我仍然遇到同样的问题....

=========

编辑2:我想我应该关注我如何发送数据,也许我错了,我有一个Object MyData:

    byte[] LargeData = File.ReadAllBytes(this.LargeDataPath.Text);
    MyData.LargeData = new List<KeyValuePair<string, byte[]>>()
    {
        new KeyValuePair<string, byte[]>("DATA", LargeData)
    };

    myServiceClient.SendDataAsync( new SendDataRequest(MyData));
Run Code Online (Sandbox Code Playgroud)

应该没有问题?我所做的只是在列表中发送一个大字节[] .....

Max*_*lov 5

您应该使用单独的发送方法调用发送较小的数据块.

将要发送的数据放入字节数组中.然后实现两端的逻辑,知道如何处理大小,并开始逐个发送数据.当您发送完整个文件后,它将连接到客户端上的数组中,您将能够进行进一步处理.