SignalR 不会使用 Chrome 或 IE 中的 VS2013 在 Windows 8 上与 IIS Express 建立连接

Posted

技术标签:

【中文标题】SignalR 不会使用 Chrome 或 IE 中的 VS2013 在 Windows 8 上与 IIS Express 建立连接【英文标题】:SignalR will not establish connection with IIS Express on Windows 8 using VS2013 from Chrome or IE 【发布时间】:2014-08-16 05:49:23 【问题描述】:

我刚开始使用 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.

我已通读Introduction to 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 方组件套件引起的。我可以关注聊天示例here,而且 SignalR 运行良好。一旦我从 DevExpress 添加一个 MVC 扩展控件,SignalR 连接协商就会中断。我在他们的支持论坛here 中对一个问题发表了评论,希望能得到答案。

感谢您提供的任何帮助!

【问题讨论】:

首先,您可以从浏览器中点击信号器集线器吗?说localhost:port/signalr/hub - 你应该看到代理,除非你禁用它。您还可以发布有关如何连接到集线器的 javascript 吗? @Gjohn 我猜代理可能被禁用(不确定如何启用),因为在 Chrome 中我收到“协议错误:未知传输”。当我导航到 /signalr/hub Url 时浏览器中的消息,我在 IE 中收到 400 Bad Request。我已使用连接到集线器的客户端脚本更新了问题。谢谢! @Gjohn - 澄清:一开始我为代理使用了错误的 URL。以 (localhost:port/signalr/hubs) 访问代理 URL 后,它确实返回了代理。 【参考方案1】:

从 DevExpress 支持团队获得一些反馈后,问题似乎出在 SignalR 2.1.0 的最新版本上。我将我的项目降级到 v2.0.3 并开始正常工作。你可以看到我与 DevExpress 支持团队的对话here。

【讨论】:

以上是关于SignalR 不会使用 Chrome 或 IE 中的 VS2013 在 Windows 8 上与 IIS Express 建立连接的主要内容,如果未能解决你的问题,请参考以下文章

SignalR 在 Chrome 上使用服务器发送的事件

SignalR 2.0 CORS Chrome 禁用 Web 安全奇怪行为

SignalR 挂起开始连接

DB 不会从 Chrome 中使用 file:/// 的链接打开

SignalR - 在 Chrome/Firefox 中始终降级为服务器发送事件

悬停不透明度在 Chrome 或 IE 中不起作用