国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
當前位置: 首頁 - 科技 - 知識百科 - 正文

HTTP協議下用Web Service上傳大文件的解決方案

來源:懂視網 責編:小采 時間:2020-11-27 22:45:27
文檔

HTTP協議下用Web Service上傳大文件的解決方案

HTTP協議下用Web Service上傳大文件的解決方案:用HTTP協議上傳大文件也許是個不好辦的問題。主要是它的不連續性,使得上傳文件感覺很危險。特別是很大的文件(幾百MB甚至是上G的文件),心里總覺得不踏實,一不小心就會出現問題,而一但出現問題就無法繼續上傳,這是很郁悶的。 后來在一些網站上找到一些
推薦度:
導讀HTTP協議下用Web Service上傳大文件的解決方案:用HTTP協議上傳大文件也許是個不好辦的問題。主要是它的不連續性,使得上傳文件感覺很危險。特別是很大的文件(幾百MB甚至是上G的文件),心里總覺得不踏實,一不小心就會出現問題,而一但出現問題就無法繼續上傳,這是很郁悶的。 后來在一些網站上找到一些

用HTTP協議上傳大文件也許是個不好辦的問題。主要是它的不連續性,使得上傳文件感覺很“危險”。特別是很大的文件(幾百MB甚至是上G的文件),心里總覺得不踏實,一不小心就會出現問題,而一但出現問題就無法繼續上傳,這是很郁悶的。

后來在一些網站上找到一些上傳文件的組件,但都是要用到一些COM組件。至于后來的ASP.net下上傳大文件的解決方案,我也做過一個組件,后來發現根本就不用自己寫什么組件,利用ASP.net自己的上傳方法也可以解決大文件上傳,真是郁悶的要死了。。

回想之后,決定用Web service來做一個文件上傳,還是利用HTTP協議,這樣不用在服務器上做太多的變動,而客戶端也簡單。

首先是解決方案的設計:因為Web service可以利用SOAP來傳遞數據,而且可以傳遞十進制數據,因此可以想到,在服務上公開一個方法,參數可以是byte數組,這樣可以把文件分塊的上傳到服務器。這一解決方法我做過,但速度很慢。后來在MS上找到一些文章,用MS最新公開的服務組件上傳文件,速度快了很多。而自己所要做的就是組織一些安全性的問題。

部份代碼:Upload Instance

代碼如下:
using System; 
using System.IO; 
using Microsoft.Web.Services2; 
using Microsoft.Web.Services2.Dime; 

namespace Webb.WAVE.WinUpload 

/**//// <summary> 
/// Summary description for Controls. 
/// </summary> 
public class UploadInstance2 

Fields#region Fields 
private string m_GUID; 
private DateTime m_uploadTime; 
private long m_fileLength; 
private long m_currentPoint; 
private string m_pathOnserver; 
private long m_userID; 
#endregion 

Properties#region Properties 
public long UserID 

get{return this.m_userID;} 
set{this.m_userID=value;} 

public string GUID 

get{return this.m_GUID;} 
set{this.m_GUID=value;} 

public DateTime UploadTime 

get{return this.m_uploadTime;} 
set{} 

public long FileLength 

get{return this.m_fileLength;} 
set{this.m_fileLength=value;} 

public long CurrentPoing 

get{return this.m_currentPoint;} 
set{this.m_currentPoint=value;} 

public string PathOnServer 

get{return this.m_pathOnserver;} 
set{this.m_pathOnserver=value;} 

public string FullPathOnServer 

get 

if(this.m_GUID!=string.Empty&&this.m_pathOnserver!=string.Empty) 

return Path.Combine(this.m_pathOnserver,this.m_GUID+".rem"); 

else 

return string.Empty; 



public string FileName 

get 

if(this.m_GUID!=string.Empty) 

return this.m_GUID+".rem"; 

else 

return string.Empty; 


#endregion 

public UploadInstance2() 

this.m_GUID = System.Guid.NewGuid().ToString(); 
this.m_uploadTime = System.DateTime.Now; 
this.m_currentPoint = 0; 
this.m_fileLength = 0; 
this.m_pathOnserver = string.Empty; 

public UploadInstance2(string i_path,string i_GUID,long i_fileLength) 

string m_fullPath = Path.Combine(i_path,i_GUID); 
if(!File.Exists(m_fullPath)) return; 
this.m_GUID = i_GUID; 
this.m_uploadTime = System.DateTime.Now; 
this.m_pathOnserver = i_path; 
FileInfo m_fileInfo = new FileInfo(m_fullPath); 
this.m_currentPoint = m_fileInfo.Length; 
this.m_fileLength = i_fileLength; 

public bool UploadData(byte[] i_data, long i_currentPoint, int i_dataSize) 

string m_fullPath = this.FullPathOnServer; 
if(!File.Exists(m_fullPath)&&this.m_currentPoint!=0)return false; 
long m_filePoint = new FileInfo(m_fullPath).Length; 
if(m_filePoint!=i_currentPoint) return false; 
FileStream m_fileStream = new FileStream(m_fullPath,FileMode.Append); 
m_fileStream.Write(i_data,0,i_dataSize); 
m_fileStream.Close(); 
return true; 

public void AbandantUpload() 

string m_fullPath = this.FullPathOnServer; 
try{File.Delete(m_fullPath);} 
catch{} 

public void CreateFile() 

string m_fullPath = this.FullPathOnServer; 
if(!File.Exists(m_fullPath)) 

File.Create(m_fullPath).Close(); 

else 

try 

File.Delete(m_fullPath); 
}catch{} 
File.Create(m_fullPath).Close(); 





上傳過程:
代碼如下:
#region UploadProcess 
public void UploadProcess() 

DateTime m_start = DateTime.Now; 
this.textBox_OutMsg.AppendText("Initialize upload\r\n"); 
if(this.m_upload==null||this.m_uploadGUID==null||this.m_uploadGUID==string.Empty) 
{  
this.textBox_OutMsg.AppendText("Upload instance id error or login to the server faild\r\n"); 
this.textBox_OutMsg.AppendText("Upload faild.\r\n"); 
return; 

this.textBox_OutMsg.AppendText("Open file\r\n"); 
if(this.m_filePath==null||this.m_filePath==string.Empty||!File.Exists(this.m_filePath)) 

this.textBox_OutMsg.AppendText("Open file error\r\n"); 
this.textBox_OutMsg.AppendText("Upload faild.\r\n"); 
return; 

FileInfo m_fileInfo = new FileInfo(this.m_filePath); 
FileStream m_fs = new FileStream(this.m_filePath, FileMode.Open, FileAccess.Read); 
this.textBox_OutMsg.AppendText("Start upload file\r\n"); 
int m_buffer = 10; //KBytes 
long m_currentPoint = 0; 
long m_fileLength = m_fileInfo.Length; 
bool m_uploadResult = false; 
byte[] m_data = new byte[m_buffer*1024]; 
long m_readBytes = m_fs.Read(m_data, 0, m_buffer*1024); 
this.UploadProcessBar.Maximum = 100; 
this.UploadProcessBar.Minimum = 0; 
while(m_readBytes>0) 

MemoryStream m_memoryStream = new MemoryStream(m_data, 0,(int)m_readBytes); 
DimeAttachment dimeAttach = new DimeAttachment("image/gif", TypeFormat.MediaType, m_memoryStream); 
this.m_upload.RequestSoapContext.Attachments.Add(dimeAttach); 
m_uploadResult = this.m_upload.UploadFileData(this.m_uploadInstance,m_currentPoint,m_readBytes); 
if(m_uploadResult) 

m_currentPoint +=m_readBytes; 
m_readBytes = m_fs.Read(m_data,0,m_buffer*1024); 
// this.textBox_OutMsg.AppendText("Uploading:"+m_currentPoint.ToString()+"/"+m_fileLength.ToString()+"\r\n"); 
this.UploadProcessBar.Value = (int)(m_currentPoint*100/m_fileLength); 
this.label_outPercent.Text = this.UploadProcessBar.Value.ToString()+"%"; 

else 

this.textBox_OutMsg.AppendText("Upload file error.\r\n"); 
m_fs.Close(); 
this.m_upload.AbandantUpload(this.m_uploadInstance); 
return; 


this.textBox_OutMsg.AppendText("File upload finished.\r\n"); 
this.button_Cancel.Enabled = false; 
m_fs.Close(); 
this.ResetForm(); 

#endregion 

測試項目代碼:
http://test.0579fw.com/myfile/kiyeer/客戶上傳/webbwinupload.zip

出現錯誤的解決方法:
*****************************************************

 引用內容
Error 1 'WinFormTest.localhost.WebbWinUpload' does not contain a definition for 'RequestSoapContext' D:\WebbWinUpload\WinFormTest\WebbWinUpload.cs 448 19 WinFormTest 

當你更新Web引用的時候,.net自動生成的Web引用為: 
public class WebbWinUpload : System.Web.Services.Protocols.SoapHttpClientProtocol 
請轉化為: 
public class WebbWinUpload : Microsoft.Web.Services2.WebServicesClientProtocol 
查找引用下自動生成的C#文件Reference.cs

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

HTTP協議下用Web Service上傳大文件的解決方案

HTTP協議下用Web Service上傳大文件的解決方案:用HTTP協議上傳大文件也許是個不好辦的問題。主要是它的不連續性,使得上傳文件感覺很危險。特別是很大的文件(幾百MB甚至是上G的文件),心里總覺得不踏實,一不小心就會出現問題,而一但出現問題就無法繼續上傳,這是很郁悶的。 后來在一些網站上找到一些
推薦度:
  • 熱門焦點

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 欧美一区二区三区四区在线观看 | 国产99精品视频 | 九九九国产在线 | 亚洲欧美日本另类 | 国产123区 | 久久国产精品电影 | 欧美专区亚洲 | 在线亚洲综合 | 欧美日韩成人午夜免费 | 久久精品一区二区三区不卡牛牛 | 日本成本人观看免费fc2 | 性夜影院爽黄a爽免费看网站 | 国产精品区一区二区三 | 亚欧精品一区二区三区 | 亚洲欧洲日韩 | 国产在线播放一区二区 | 欧美精品在线视频观看 | 国产高清美女一级a毛片久久 | 亚洲欧美在线免费观看 | 国产成人一区二区三区在线播放 | 小说区 亚洲 自拍 另类 | 国产国语高清在线视频二区 | 香蕉久久网 | 视频二区 素人 欧美 日韩 | 国产 日韩 欧美在线 | 热久久国产欧美一区二区精品 | 福利视频一区二区 | 欧美日韩视频一区三区二区 | 国产最新在线视频 | 综合毛片 | 日本久久久久久久 | 日韩二三区 | 久久精品国产国产精品四凭 | 亚洲国产精品热久久2022 | 欧美二区三区 | 香港经典a毛片免费观看…伊人色综合久久 | 91精品久久久久 | 最新国产精品视频免费看 | 欧美日韩免费一区二区在线观看 | 中文字幕另类 | 精品72久久久久久久中文字幕 |