我正在使用 WCF 上传和下载文件。我正在使用以下下载。
try
{
MyService.IWITSService clientDownload = new WITSServiceClient();
MyService.DownloadRequest requestData = new DownloadRequest();
MyService.RemoteFileInfo fileInfo = new RemoteFileInfo();
requestData.ItemID = Convert.ToInt32(Request.QueryString["id"]);
fileInfo = clientDownload.DownloadFile(requestData);
Response.BufferOutput = false; // to prevent buffering
byte[] buffer = new byte[6500000];
int bytesRead = 0;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ContentType = fileInfo.FileExt;
HttpContext.Current.Response.AddHeader("Content-Disposition","attachment; filename=" + fileInfo.FileName);
bytesRead = fileInfo.FileByteStream.Read(buffer, 0, buffer.Length);
while (bytesRead > 0)
{
// Verify that the client is connected.
if (Response.IsClientConnected)
{
Response.OutputStream.Write(buffer, 0, bytesRead);
// Flush the data to the HTML output.
Response.Flush();
buffer = new byte[6500000];
bytesRead = fileInfo.FileByteStream.Read(buffer, 0, buffer.Length);
}
else
{
bytesRead = -1;
}
}
}
catch (Exception ex)
{
// Trap the error, if any.
System.Web.HttpContext.Current.Response.Write("Error : " + ex.Message);
}
finally
{
Response.Flush();
Response.Close();
Response.End();
System.Web.HttpContext.Current.Response.Close();
}
文件已下载,但不显示文件数据。文件大小与实际大小相同。任何人都可以帮助我在我必须改变的地方..提前谢谢..