我下载了Sample SignalR Progress Bar解决方案。它模拟服务器上长时间运行的进程,使用 SignalR 不断更新客户端。它在 IISExpress 上完美运行,直到我在控制器中为我的方法添加File.Copy(source, destination, true)
(见下文)。
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.js 时,当 onclose 事件引发时,错误代码 1000 。
我还在SignalR website上提出了一个问题。如果你能提出任何方法来找出发生这种情况的原因,我将不胜感激。
更多信息:
答案 0 :(得分: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("~/") + @"\";
解决了我的问题。