l******9 发帖数: 579 | 1 大于 64KB 文件不能下载 (from C# code). 大于 文件不能完全下载, 只能下载 64KB
, 然后
truncated. Why ?
I have published a web service application (C# built in VS2010) to a desktop
with IIS 7.5 win7.
The web service has been hosted successfully on win 7.
Now I can install the application on my laptop (win 7) by accessing the URL
http://myDesktopName.domain.com/MyApp/MyAppSetup.msi
pointing to a physical location in desktop
E:myPathmyAppmyAppService.svc
Now, in my application, I need to download (from C# on my laptop) a .dat
file from my desktop to my local laptop by visiting the URL. The downlod
function is
webclient.downloadfile(URL, myLocalFileName)
https://msdn.microsoft.com/en-us/library/ms144194%28v=vs.110%29.aspx.
The URL is
"http://myDesktopName.domain.com/MyApp/download.ashx?cmd=download&type=db&name=myDatasbase.dat"
But, the downloaded file size is not correct. Sometimes, it is 0. Sometimes,
it is 64KB. But, the original size s 4,000 KB.
If the file size is larger than 64KB, none of them can bne downloaded. I got
error:
**connection was forcibly closed by remote server**
on my laptop, and
**error 504 gateway timeout**
on my desktop.
The file is binary and is not readable in any text editor.
If I download the file from IE by visiting the same URL in address bar, the
file can be downloaded correctly.
Why the file cannot be downloaded correctly from my application if it is
larger than 64 KB? I have set up minbytepersec as 0 in IIS on my desktop and
set worker process as 8 for the application pool. And, increase timeout to
10 minutes.
Is this a bug of win 7 ? because I found this at
https://support.microsoft.com/en-us/kb/919797?wa=wsignin1.0
but, it is about win server 2003. My OS is win 7.
I have done a lot of search about the error of 504 and connection-closed by
remote server, but none of them work.
In the IIS manager, ASP limit,
max requesting entity body limit = 1073741824 // 1024 MB
max allowed content length = 30000000 bytes // 28 MB
I think it should be large enought to download a 4MB file.
But, it still failed for any file size > 64 KB.
this is C# code ran at VS2010.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Diagnostics;
namespace datafile_updownload
{
class Program
{
static void Main(string[] args)
{
try
{
WebClient _client;
_client = new WebClient();
// download
// An ASP.net web service has been published on my myDesktopName
with IIS7.5
string url = "http://myDesktopName.domain.com/MyApp/download.ashx?cmd=download&type=db&name=myFile";
Uri uri = new Uri(url);
string tmp = @"C:\Temp\aFile.dat";
_client.DownloadFile(uri, tmp); // **if file size > 64KB**, **
exception jumped out here,**
// Unable to read data from the transport
connection: An existing connection was
// forcibly closed by the remote host.
// System.Net.WebExceptionStatus.UnknownError
}
catch(WebException ex)
{
Console.WriteLine("This program is expected to throw
WebException on unsuccessful run." +
"\n\nException Message :" + ex.Message);
Console.WriteLine("Status : {0}", (ex.Status));
Console.WriteLine("Response: {0}", (ex.Response));
}
}
}
} |
|