private void btnDownload2_Click(object sender, EventArgs e) { string fileName = SelectFile(); if (string.IsNullOrEmpty(fileName)) { return; } this.Cursor = Cursors.WaitCursor; DownFileRequest req = new DownFileRequest(fileName); BasicHttpBinding binding = new BasicHttpBinding(); binding.TransferMode = TransferMode.Streamed; binding.MessageEncoding = WSMessageEncoding.Mtom; binding.MaxReceivedMessageSize = 9223372036854775807; IUpLoadService channel = ChannelFactory <IUpLoadService> .CreateChannel(binding, new EndpointAddress("http://localhost:62805/UpLoadService.svc")); using (channel as IDisposable) { var res = channel.DownLoadFile(req); if (res.IsSuccess) { using (var fileStream = File.Create(AppDomain.CurrentDomain.BaseDirectory + "\\" + fileName.Substring(fileName.LastIndexOf('\\') + 1))) { CopyTo(res.FileStream, fileStream); } } this.Cursor = Cursors.Default; MessageBox.Show(res.IsSuccess ? "文件下载成功!" : res.Message, "上传文件测试", MessageBoxButtons.OK, res.IsSuccess ? MessageBoxIcon.Information : MessageBoxIcon.Error); } }
private void btnDownLoad1_Click(object sender, EventArgs e) { string fileName = SelectFile(); if (string.IsNullOrEmpty(fileName)) { return; } this.Cursor = Cursors.WaitCursor; DownFileRequest req = new DownFileRequest(fileName); IUpLoadService svc = new UpLoadServiceClient(); var res = svc.DownLoadFile(req); if (res.IsSuccess) { using (var fileStream = File.Create(AppDomain.CurrentDomain.BaseDirectory + "\\" + fileName.Substring(fileName.LastIndexOf('\\') + 1))) { CopyTo(res.FileStream, fileStream); } } this.Cursor = Cursors.Default; MessageBox.Show(res.IsSuccess?"文件下载成功!":res.Message, "上传文件测试", MessageBoxButtons.OK, res.IsSuccess ? MessageBoxIcon.Information : MessageBoxIcon.Error); }