我正在客户端使用以下代码将数据从客户端传输到服务器。
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>
我们还有其他方法可以解决不良请求问题。