看起來即時通訊面臨一個問題。我有.NET + Flex應用程序。C#WebServices和Flex RPC會話不起作用
我有一個Flex組件,他將一個.XLS文件上傳到服務器。 該組件有一個Progress Bar
,並將其與fileref.addEventListener(ProgressEvent.PROGRESS, progressHandler);
private function progressHandler(event:ProgressEvent):void
{
uploadProgress.label = "Uploading File %3%%";
uploadProgress.setProgress(event.bytesLoaded, event.bytesTotal);
}
我用的FileReference和所有的事情acomplish此更新其欄和標籤。我在服務器中發佈文件的東西保存這樣
HttpFileCollection uploadedFiles = Request.Files;
string path = string.Empty;
string sFile = Request.Params["Name"];
if (uploadedFiles.Count != 0)
{
HttpPostedFile userPostedFile = uploadedFiles[0];
if (userPostedFile.ContentLength > 0)
{
path = Server.MapPath(".\\Uploads\\") + sFile;
userPostedFile.SaveAs(path);
}
}
這工作完全正常,我的吧,我的標籤被刷新ok了,我的文件在Temp文件夾上傳並一切正常,所以回到到Flex我可以通過DataEvent.UPLOAD_COMPLETE_DATA
上傳文件。 因此,當調度此事件時,我調用Web服務的WebMethod來讀取已發佈的文件並遍歷所有記錄。該文件可能有65,000多行。因此,在某些表中,信息在Oracle DB中逐行更新。
我試圖實現的是當文件發佈到服務器時具有相同的效果。我想要一個進度條並顯示上載到Oracle DB的行的百分比。
所以我在Flex中做的是這樣的:
//Service is the WebService Instance
ShowPopUpProgress();
Service.wsUploadFileToDb(FileName);
Service.wsUpdatePercentage();
protected function wsUpdatePercentage_result(event:ResultEvent):void
{
compProgress.uploadProgress.label = "Uploading to DB %3%%";
compProgress.uploadProgress.setProgress(event.result.Actual, event.result.Total);
if(event.result.Actual != event.result.Total)
{
Service.wsUpdatePercentage();
}
else
{
RemovePopUpProgress();
}
}
而在C#我這樣做
[WebMethod(EnableSession = true)]
public void wsUploadFileToDb(string fileName)
{
HttpContext.Current.Session["Total"] = 0;
HttpContext.Current.Session["Actual"] = 0;
//... And in the Loop
HttpContext.Current.Session["Total"] = myDataTable.Rows.Count;
for (int i = 0; i < myDataTable.Rows.Count; i++)
{
HttpContext.Current.Session["Actual"] = i + 1;
}
}
[WebMethod(EnableSession = true)]
[XmlInclude(typeof(Percentage))]
public Percentage wsUpdatePercentage()
{
Percentage oPercentage= new Percentage();
if (HttpContext.Current.Session["Total"] != null)
{
oPercentage.Total = Convert.ToInt32(HttpContext.Current.Session["Total"]);
oPercentage.Actual= Convert.ToInt32(HttpContext.Current.Session["Actual"]);
}
}
我不知道在這一點上,你明白我想做的事。我不知道這是最好的方式,還是有另一種方法來實現我的目標。但那就是我所擁有的。由於某種原因,這是行不通的,會話變量正確存儲在 wsUploadFileToDb方法,但我無法看到他們在wsUpdatePercentage,他們只是不「共享」會話。我調試了這兩種方法,會話ID是不同的。所以會話不被共享。我不知道還有什麼要做。我在網站上的第一頁是一個aspx ..我在會話中放置了一個虛擬變量,因爲我在一篇文章中讀到你必須這樣做,在web服務中啓動會話,但仍然不是運氣。
任何幫助將非常感激。
在此先感謝。
感謝您的回覆,我在第一時間就想到了這一點,但我不想放慢這個過程。但是我沒有在這方面看到它,有一個審計日誌。讓我試試看,並檢查它的性能。謝謝。 –
我這樣做,它運行良好,它不能解決有關會話的問題......但它解決了問題。感謝:D –