2017-04-02 108 views
0

我下載了Sample SignalR Progress Bar解決方案。它模擬服務器上長時間運行的進程,持續更新客戶端,使用SignalR。它在IISExpress完美工作,直到我在控制器中添加File.Copy(source, destination, true)我的方法(見下文)。獲取WebSocket錯誤:使用File.Copy與SignalR時出現網絡錯誤12030

public JsonResult LongRunningProcess() 
{ 
    string directory = Server.MapPath("~/bin/") + @"\"; 

    string source = directory + @"Templates\Template.xlsx"; 
    string destination = directory + @"Spreadsheets\output file.xlsx"; 
    System.IO.File.Copy(source, destination, true); 

    for (int i = 0; i <= 50; i++) 
    { 
     Thread.Sleep(500); 
     Functions.SendProgress("Process in progress...", i , 50); 
    } 

    return Json("", JsonRequestBehavior.AllowGet); 
} 

現在我收到服務器端的一個WebSocketException:在客戶端

SignalR.Transports.WebSocketTransport Error: 0 : OnError(7bdc2904-8f12-4324-898f-58e4a9f4e686, System.Net.WebSockets.WebSocketException (0x800703E3): The I/O operation has been aborted because of either a thread exit or an application request 
    at System.Web.WebSockets.WebSocketPipe.<>c__DisplayClass9_0.<ReadFragmentAsync>b__0(Int32 hrError, Int32 cbIO, Boolean fUtf8Encoded, Boolean fFinalFragment, Boolean fClose) 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at System.Web.WebSockets.AspNetWebSocket.<DoWork>d__45`1.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at System.Web.WebSockets.AspNetWebSocket.<>c__DisplayClass36_0.<<ReceiveAsyncImpl>b__0>d.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.AspNet.SignalR.WebSockets.WebSocketMessageReader.<ReadMessageAsync>d__3.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.AspNet.SignalR.WebSockets.WebSocketHandler.<ProcessWebSocketRequestAsync>d__25.MoveNext()) 

和WebSocket的錯誤:

SCRIPT12030: WebSocket Error: Network Error 12030, The connection with the server was terminated abnormally 
[time] SignalR: Unclean disconnect from websocket: 
[time] SignalR: Closing the Websocket. 

當我檢查jQuery.signalr-2.2。 1.jsonclose事件引發,錯誤代碼爲。

我還在SignalR website上提出了一個問題。如果您能以任何方式找出發生這種情況的原因,我將不勝感激。

更多信息:

  • 它發生在Internet Explorer以及谷歌瀏覽器,因爲我 測試。
  • 2015年,我在Visual Studio 上使用SignalR 2.2.1和.NET Framework 4.5.2,但我也嘗試了不同的SignalR版本(2.0.2)。

回答

0

我終於找到了如何解決這個問題。我試圖讓在Bin文件夾這裏的變化:

string directory = Server.MapPath("~/bin/") + @"\"; 

string source = directory + @"Templates\Template.xlsx"; 
string destination = directory + @"Spreadsheets\output file.xlsx"; 
System.IO.File.Copy(source, destination, true); 

是導致IIS回收應用領域,因此,SignalR連接復位,並拋出一個WebSocketException。因此,將第一行更改爲:

string directory = Server.MapPath("~/") + @"\"; 

解決了我的問題。