我写了以下代码,但它不起作用。将文件上载到Web服务时出现以下错误:
1.An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full
2.The underlying connection was closed: An unexpected error occurred on a send.
我已经为Web服务使用了以下代码,当文件大小超过90 mb时,出现错误:
LocalService.IphoneService obj = new LocalService.IphoneService();
byte[] objFile = FileToByteArray(@"D:\Brijesh\My Project\WebSite5\IMG_0010.MOV");
int RtnVal = obj.AddNewProject("demo", "demo", "demo@demo.com", "demo@demo.com", 1, 2, 29, "IMG_0010.MOV", objFile,"00.00.06");
public byte[] FileToByteArray(string fileName)
{
byte[] fileContent = null;
System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(fs);
long byteLength = new System.IO.FileInfo(fileName).Length;
//byteLength = 94371840;
fileContent = binaryReader.ReadBytes((Int32)byteLength);
fs.Close();
fs.Dispose();
binaryReader.Close();
return fileContent;
}
答案 0 :(得分:1)
没有套接字会在一个块中传输200MB。您将以块的形式接收数据,大多数在1024到4096字节之间(取决于您的设置)。
对于asp.net webservice:
enable webservice to receive large amounts of data
增加对SOAP消息的最大大小的ASP.NET限制 允许执行请求的最大秒数 将配置元素添加到应用程序中 web.config文件。以下代码示例设置ASP.NET限制 传入请求的最大大小为400MB且最大 允许请求执行到5分钟的时间(300 秒)。
将它放在你的web.config中。
<configuration>
<system.web>
<httpRuntime maxMessageLength="409600"
executionTimeoutInSeconds="300"/>
</system.web>
</configuration>
请记住,只要处理此请求,您就会阻止线程。这不会扩展到大量用户。