我刚刚开始使用 SignalR,所以如果我忽略了一些超级基本的东西,请原谅我。我的目标是为用户提供一个“保留页面”,直到特定事件发生在服务器端,告诉该页面将用户带到流程的下一步。我在服务器上创建了一个集线器,当客户端在服务器上调用调用时它似乎可以正常工作。
问题是客户端从未收到来自服务器的任何调用,并且从浏览器控制台输出看来客户端从未与集线器建立必要的连接。
我已经在最新的 Google Chrome 和 MS IE v11 中尝试过。我在每个浏览器中都记录了相同的消息。
下面是 MS IE 的浏览器控制台输出(我找不到将 Chrome 控制台输出保存为文本的简单方法):
[10:32:02 GMT-0400 (Eastern Daylight Time)] SignalR: Client subscribed to hub 'signinghub'.
[10:32:02 GMT-0400 (Eastern Daylight Time)] SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22signinghub%22%7D%5D'.
[10:32:02 GMT-0400 (Eastern Daylight Time)] SignalR: Connecting to websocket endpoint 'ws://localhost:53915/signalr/connect?transport=webSockets&clientProtocol=1.4&connectionToken=orv901EJmuVZdJis9VFLBMVTl8bgZlbK5pWdAxiugZiYOCPPxytCCjewTQ%2FxcM0bMcGxDdRY6T46ApZSWnL%2BRO8kkllhVhYr1ZROWGSdyFQ2580j%2BR6lXitPVhdXncon&connectionData=%5B%7B%22name%22%3A%22signinghub%22%7D%5D&tid=8'.
[10:32:02 GMT-0400 (Eastern Daylight Time)] SignalR: Websocket opened.
[10:32:07 GMT-0400 (Eastern Daylight Time)] SignalR: webSockets timed out when trying to connect.
[10:32:07 GMT-0400 (Eastern Daylight Time)] SignalR: Closing the Websocket.
[10:32:07 GMT-0400 (Eastern Daylight Time)] SignalR: This browser doesn't support SSE.
[10:32:07 GMT-0400 (Eastern Daylight Time)] SignalR: Binding to iframe's load event.
[10:32:12 GMT-0400 (Eastern Daylight Time)] SignalR: foreverFrame timed out when trying to connect.
[10:32:12 GMT-0400 (Eastern Daylight Time)] SignalR: Stopping forever frame.
[10:32:12 GMT-0400 (Eastern Daylight Time)] SignalR: Opening long polling request to 'http://localhost:53915/signalr/connect?transport=longPolling&clientProtocol=1.4&connectionToken=orv901EJmuVZdJis9VFLBMVTl8bgZlbK5pWdAxiugZiYOCPPxytCCjewTQ%2FxcM0bMcGxDdRY6T46ApZSWnL%2BRO8kkllhVhYr1ZROWGSdyFQ2580j%2BR6lXitPVhdXncon&connectionData=%5B%7B%22name%22%3A%22signinghub%22%7D%5D&tid=4'.
[10:32:13 GMT-0400 (Eastern Daylight Time)] SignalR: Long poll complete.
[10:32:13 GMT-0400 (Eastern Daylight Time)] SignalR: Opening long polling request to 'http://localhost:53915/signalr/poll?transport=longPolling&messageId=d-65C891D3-Q%2C0%7CU%2C0%7CV%2C3%7CW%2C0&clientProtocol=1.4&connectionToken=orv901EJmuVZdJis9VFLBMVTl8bgZlbK5pWdAxiugZiYOCPPxytCCjewTQ%2FxcM0bMcGxDdRY6T46ApZSWnL%2BRO8kkllhVhYr1ZROWGSdyFQ2580j%2BR6lXitPVhdXncon&connectionData=%5B%7B%22name%22%3A%22signinghub%22%7D%5D&tid=10'.
[10:32:17 GMT-0400 (Eastern Daylight Time)] SignalR: longPolling timed out when trying to connect.
[10:32:17 GMT-0400 (Eastern Daylight Time)] SignalR: Aborted xhr request.
[10:32:17 GMT-0400 (Eastern Daylight Time)] SignalR: Stopping connection.
[10:32:17 GMT-0400 (Eastern Daylight Time)] SignalR: Fired ajax abort async = true.
我已经阅读了SignalR 简介,并且知道它将尝试从最受青睐的通信技术故障转移到最不受欢迎的通信技术。据我所知,它正在尝试所有 4 种方法进行通信,但每种方法都失败了,最终放弃了“停止连接”。信息。
我正在使用 VS 2013 和 IIS Express 进行开发、SignalR v2.1.0 和 ASP.NET MVC 5。
更新包括客户端代码
以下是客户端中用于连接集线器的脚本:
<!--Reference the SignalR library. -->
<script src="~/Scripts/jquery.signalR-2.1.0.min.js" type="text/javascript"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="~/signalr/hubs"></script>
<script>
$.connection.hub.logging = true;
$(function () {
// Reference the auto-generated proxy for the hub.
var chat = $.connection.signingHub;
// Create a function that the hub can call back to redirect the user
chat.client.signDocument = function () {
// Add the message to the page.
window.location.assign("/Signing/Initiate/" + ContractID.value + "?clientUserId=" + ClientUserId.value);
};
// Start the connection.
$.connection.hub.start();
});
</script>
更多信息...
我发现这可能是由我从 DevExpress 使用的第 3 方组件套件引起的。我可以按照此处的聊天示例进行操作,并且 SignalR 运行良好。一旦我从 DevExpress 添加一个 MVC 扩展控件,SignalR 连接协商就会中断。我在他们的支持论坛中评论了一个问题,希望能得到答案。
感谢您的任何帮助,您可以提供!