我遇到了SignalR奇怪的行为。经过一些重构后,我遇到了连接问题。我认为这是纯粹的运气,因为代码不符合推荐的做法。比如我开始之前枢纽我声明了轮毂的方法(如David Fowler解释),所以客户端从来没有明确订阅的集线器但不知何故,他们做到了。我整天看着为什么,但没有运气。SignalR冻结在“启动启动请求”
重构之后这是执行一次文件被加载代码:
function initSignalR() {
var me = this,
appointmentHub = $.connection.appointmentHub,
assignmentHub = $.connection.assignmentHub,
taskHub = $.connection.taskHub,
notificationHub = $.connection.notificationHub,
messageHub = $.connection.messageHub;
$.connection.hub.connectionSlow(onConnectionSlow);
$.connection.hub.stateChanged(onStateChanged);
$.connection.hub.error(onError);
$.connection.hub.disconnected(onDisconnected);
$.connection.hub.logging = true;
appointmentHub.client.updateAppointment = onUpdateAppointment;
$.connection.hub.start().done(onDone).fail(onFailed);
... code ommitted for brevity ...
}
function onUpdatedAppointment(appointment) {
.... code ommitted for brevity ....
}
这些是出现在控制台日志时,偶尔工作:
Client subscribed to hub 'appointmenthub' Negotiating with '/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22appointmenthub%22%7D%5D' webSockets transport starting. Connecting to websocket endpoint 'ws://localhost:52541/signalr/connect?.... Websocket opened. webSockets transport connected. Initiating start request. The start request succeeded. Transitioning to the connected state. Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000
我因为每时每刻SignalR连接正确,所以写了'偶然'的意图。可悲的是,大部分时间我都没有那么远。通常控制台中最后一个可见的步骤是:
webSockets传输已连接。发起启动请求。
一段时间以来,我认为这是回调方法的主体,导致我可以连接更多的问题,当我有一个空功能,但即使这不是原因。所以我想下一步该做什么。
为了完整起见,这里是在ASP.NET MVC的启动代码:
GlobalHost.Configuration.TransportConnectTimeout = TimeSpan.FromSeconds(50);
GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(110);
GlobalHost.HubPipeline.AddModule(new ErrorHandlingPipelineModule());
GlobalHost.DependencyResolver.Register(typeof(IJavaScriptMinifier),() => new SignalRMinifier());
GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider),() => new UserIdProvider());
HubConfiguration hubConfiguration = new HubConfiguration()
{
EnableDetailedErrors = true,
};
return app.MapSignalR(hubConfiguration);
我发现了一个similar issue,但没有解决方案已经只要有。
我在IE/EDGE /镀铬/火狐/歌剧测试这一点,都具有相同的结果。该应用程序在ASP.NET MVC5上运行,并使用最新版本的SignalR(2.2.1)。