WCF 传输 Byte[] 部分代码
//客户端调用 using (FileStream fs = new FileStream(sourceFilePath, FileMode.Open)) { byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, bytes.Length); // 设置当前流的位置为流的开始 fs.Seek(0, SeekOrigin.Begin); fs.Close(); fs.Dispose(); var client = new MvcCallWCFService.UnZipFileService.ZipServiceClient(); client.DoWork(); client.ZipFileUpload(bytes, "22-140-133", "bl96"); }
byte[] bytes = streamBytes; // 把 byte[] 写入文件 var path = GetTempPath(); //创建文件夹地址(不存在就创建) CreateDirectory(path); //指定文件保存格式 var filePath = path + @"\A.Zip"; //写入本地临时文件 using (FileStream fs = new FileStream(filePath, FileMode.Create)) { BinaryWriter bw = new BinaryWriter(fs); bw.Write(bytes); bw.Close(); fs.Close(); }
/// <summary> /// 得到临时文件 /// </summary> /// <returns></returns> private string GetTempPath() { //获取一个临时文件夹 string tempPath = Path.GetTempPath(); string savePath = tempPath + @"UnZipTemp" + new Random().Next(20).ToString(); CreateDirectory(savePath); return savePath; }