【问题标题】:How to transfer the large date from client to server?如何将大数据从客户端传输到服务器?
【发布时间】:2015-08-01 07:43:00
【问题描述】:

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

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();
}

如果我发送它给出错误请求的大文件,这适用于小文件。 我也在 web.config 中指定了大小限制,但它给出了同样的例外

<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>

是否有其他方法可以解决错误请求问题。

【问题讨论】:

  • 请注意将代码示例格式化为可读状态。

标签: c# wcf


【解决方案1】:
  1. 将 transferMode 替换为 Streamed
  2. 从服务器返回流而不是字节数组 您可以找到示例 herehere

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多