新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
正確處理WCF文件及解決方案
雖然有許多人對WCF文件的使用性表示懷疑,但在年復(fù)一年的不斷發(fā)展中,但前提是要深入理解到底什么是WCF文件,及WCF是怎么運作的。 下面就對WCF文件進(jìn)行深一步的介紹。。。

成都創(chuàng)新互聯(lián)專注于企業(yè)成都全網(wǎng)營銷、網(wǎng)站重做改版、章丘網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5場景定制、商城網(wǎng)站定制開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為章丘等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
這樣,既不用添加服務(wù)引用,也不需要生成代理。文件傳輸?shù)暮瘮?shù)不是很難,代碼如下:
- publicvoidTransferFile(FileTransferMessagerequest)
- {
- stringlogInfo;
- Program.Get_ILog().Log(logInfo=string.Format("開始接收文件,name={0}",request.FileName));//填寫日志
- //文件信息
- stringuploadFolder=AppValue.GetParam()._saveDir;
- stringsavaPath=request.SavePath;
- stringfileName=request.FileName;
- StreamsourceStream=request.FileData;
- FileStreamtargetStream=null;
- //判斷文件是否可讀
- if(!sourceStream.CanRead)
- {
- thrownewException("數(shù)據(jù)流不可讀!");
- }
- if(savaPath==null)savaPath=@"文件傳輸\";
- if(!savaPath.EndsWith("\\"))savaPath+="\\";
- if(!uploadFolder.EndsWith("\\"))uploadFolder+="\\";
- uploadFolderuploadFolder=uploadFolder+savaPath;
- //創(chuàng)建保存文件夾
- if(!Directory.Exists(uploadFolder))
- {
- Directory.CreateDirectory(uploadFolder);
- }
- intfileSize=0;
- stringfilePath=Path.Combine(uploadFolder,fileName);//Combine合并兩個路徑
- try
- {
- 文件流傳輸
- using(targetStream=newFileStream(filePath,FileMode.Create,FileAccess.Write,FileShare.None))
- {
- 定義文件緩沖區(qū)
- constintbufferLen=4096;
- byte[]buffer=newbyte[bufferLen];
- intcount=0;
- while((count=sourceStream.Read(buffer,0,bufferLen))>0)
- {
- targetStream.Write(buffer,0,count);
- fileSize+=count;
- }
- targetStream.Close();
- sourceStream.Close();
- }
- }
- catch(Exceptionex)
- {
- Program.Get_ILog().Log(logInfo+ex.Message);
- }
- Program.Get_ILog().Log(string.Format("接收文件完畢name={0},filesize={1}",
- request.FileName,fileSize));
- }
WCF文件其他的代碼感興趣的朋友下載來研究吧!
當(dāng)前標(biāo)題:正確處理WCF文件及解決方案
當(dāng)前網(wǎng)址:http://m.fisionsoft.com.cn/article/cdjicee.html


咨詢
建站咨詢
