解决方案:
1. 在目标服务器上发布webservice,实现文件下载的方法。
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.IO; using System.Data; namespace TRNWebService { /// <summary> /// FileHelperService 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 // [System.Web.Script.Services.ScriptService] public class FileHelperService : System.Web.Services.WebService { /// <summary> /// 从指定文件夹下获取文件 /// </summary> /// <param name="dicpath"></param> /// <returns></returns> [WebMethod(EnableSession = true, Description = "获取文件夹下面的文件")] public DataTable GetFileList(string dicpath) { DataTable dt = new DataTable(); dt.TableName = "AEFiles"; dt.Columns.Add("fileName", typeof(string)); dt.Columns.Add("filePath", typeof(string)); DirectoryInfo dir = System.IO.Directory.CreateDirectory(dicpath); if (dir == null) { return null; } FileInfo[] files = dir.GetFiles(); for (int i = 0; i < files.Length; i++) { FileInfo file = files[i] as FileInfo; if (file != null) { dt.Rows.Add(file.Name, file.FullName); } } return dt; } [WebMethod(Description = "下载服务器站点文件,传递文件相对路径")] public byte[] DownloadFile(string strFilePath) { FileStream fs = null; //string CurrentUploadFolderPath = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["UploadFileFolder"]); //string CurrentUploadFilePath = CurrentUploadFolderPath + strFilePath; string CurrentUploadFilePath = strFilePath; if (File.Exists(CurrentUploadFilePath)) { try { ///打开现有文件以进行读取。 fs = File.OpenRead(CurrentUploadFilePath); int b1; System.IO.MemoryStream tempStream = new System.IO.MemoryStream(); while ((b1 = fs.ReadByte()) != -1) { tempStream.WriteByte(((byte)b1)); } return tempStream.ToArray(); } catch (Exception ex) { return new byte[0]; } finally { fs.Close(); } } else { return new byte[0]; } } } }