首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >获取WebSocket错误:当使用File.Copy和SignalR时网络错误12030

获取WebSocket错误:当使用File.Copy和SignalR时网络错误12030
EN

Stack Overflow用户
提问于 2017-04-02 03:20:48
回答 1查看 1.1K关注 0票数 0

我下载了样本SignalR进度条解决方案。它模拟服务器上长时间运行的进程,使用SignalR不断更新客户端。它在IISExpress上运行得很好,直到我在控制器中向我的方法添加了一个File.Copy(source, destination, true) (参见下面)。

代码语言:javascript
运行
复制
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:

代码语言:javascript
运行
复制
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错误:

代码语言:javascript
运行
复制
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,事件时选中时,错误代码是1000。

我还在SignalR网站上提出了一个问题。如果你能提出任何办法找出这件事发生的地点/原因,我将不胜感激。

更多信息:

  • 正如我所测试的,它发生在Internet和Google中。
  • 我在Visual 2015上使用SignalR 2.2.1和.NET Framework4.5.2,但我也尝试了不同的SignalR版本(2.0.2)。
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-03 04:53:30

我终于找到了解决这个问题的办法。我试图在Bin文件夹中进行以下更改:

代码语言:javascript
运行
复制
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。因此,将第一行更改为:

代码语言:javascript
运行
复制
string directory = Server.MapPath("~/") + @"\";

解决了我的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43164272

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档