如何将大数据从客户端传输到服务器

本文关键字:客户端 传输 服务器 数据 | 更新日期: 2023-09-27 18:06:03

我在客户端使用以下代码将数据从客户端传输到服务器。

FileStream fs = new FileStream(FilePath + dsBlockImages.Tables[0].Rows[i]["ImageName"].ToString(), FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
eventLog1.WriteEntry(buffer.Length.ToString());
using (MemoryStream ms = new MemoryStream(buffer))
{
    proxy.GetAllModuleDocumentsForServerSyncUp(buffer, dsBlockImages.Tables[0].Rows[i]["ImageName"].ToString(), fileindication);
}
在服务器中,我在WCF服务 中编写了以下代码
if (!File.Exists(System.Web.Hosting.HostingEnvironment.MapPath(filetargetpath) + FileName))
{
    FileStream writeStream = new FileStream(System.Web.Hosting.HostingEnvironment.MapPath(filetargetpath) + FileName, FileMode.Append, FileAccess.Write);
    writeStream.Write(buffer, 0, buffer.Length);
    writeStream.Close();
}

这是为小文件工作,如果我发送大文件,它是错误的请求。我已经指定了网页的大小限制。配置也,但它给出相同的异常

<binding name="BasicHttpBinding_ISyncUpService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
    <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. 将transferMode替换为streaming
  2. 从服务器返回流而不是字节数组你可以在这里和这里找到例子