从服务器到客户端方法的SignalR Hub(在云中)回调的间歇性问题 [英] Intermittent problems with SignalR Hubs (in the Cloud) callback from Server to Client method

查看:164
本文介绍了从服务器到客户端方法的SignalR Hub(在云中)回调的间歇性问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,SignalR Hubs已经在我的开发机器上与IIS 7.5中的本地托管网站完美配合。我让客户端在点击事件上向服务器发出信号器调用,然后服务器在将响应发送回客户端上的回调方法之前执行20秒的线程延迟。这适用于所有浏览器。但是,当我将应用程序部署到Windows Azure云时,SignalR开始出现这些间歇性问题。具体来说,服务器在客户端上达到回调方法似乎存在问题。我通过观看Chrome开发工具中的网络流量来验证这一点。我可以清楚地看到POST连接是由signalr做出的。它处于挂起状态20秒,然后当服务器响应时POST成功完成。但是,客户端的回调方法(带有简单的警报消息)并不总是由于某种原因而触发。注意:在我的测试中,我注意到一些奇怪的行为,当回调方法没有触发时,我可以通过正常下载文件来解决它(通过使用href = window.baseUrl +'/ CloudStorage / DownloadZip?' )然后单击触发信号器的按钮。正如我在网络流量中看到这一点,不知何故window.baseUrl BOM命令触发信号器重新连接。非常感谢任何帮助!

So far, SignalR Hubs has been working perfectly with a locally hosted website in IIS 7.5 on my dev machine. I have the client making a signalr call to the server on a click event, then the server does a 20 second thread delay before sending a response back to the callback method on the client. This works consistently across all browsers. However, when I deploy my application to the Windows Azure Cloud, SignalR begins to have these intermittent problems. Specifically, there seems to be a problem with the server reaching the callback method on the client. I verified this by watching the network traffic in Chrome Dev Tools. I can clearly see the POST connection being made out by signalr. It sits in "pending" status for 20 seconds and then the POST successfully completes when the server responds back. However, the callback method (with a simple alert message) on the client-side doesn't always fire for some reason. NOTE: In my testing, I noticed some strange behavior that when the callback method is not firing, I could get it to fire by doing a normal download of a file (by using href = window.baseUrl + '/CloudStorage/DownloadZip?') and then clicking on the button that triggers the signalr. As I'm watching this in network traffic, somehow that window.baseUrl BOM command triggers the signalr to do a reconnect. Would appreciate any help!

编辑:我正在使用IE 10,最新的Chrome和最新的Firefox进行所有测试。当应用程序在云端时,IE 10似乎与signalr有最多的问题,这对我来说有点奇怪,因为这是一个MS产品。另外,我使用的是SignalR版本1.1.2。

I am using IE 10, latest Chrome, and latest Firefox for all my testing. IE 10 seems to have the most issues with signalr when the app is in the cloud, which is a little strange to me since this is an MS product. Also, I'm using version 1.1.2 of SignalR.

以下是我的代码片段:

SERVER SIDE:

SERVER SIDE:

[HubName("MultiFile")]
public class MultiFile : Hub
{      

    [HubMethodName("Send")]
    public void Send(string DocID)
    {
        System.Threading.Thread.Sleep(20000);

        // Call the addMessage method on caller client            
        Clients.Caller.addMessage(DocID);
    }

}

客户端:

        $('#dBtn').click(function () {
        var docIds = sceneLayoutService.getSelection();
        var href;
        var docIdsParam;
        if (docIds.length === 0) {               
            // signalr test code below
            // Proxy created on the fly          
            var test_connection = $.connection.MultiFile;

            // Declare a function on the MultiFile hub so the server can invoke it
            test_connection.client.addMessage = function (message) {
                alert(message);
            };

            // Start the connection
            $.connection.hub.start().done(function () {
                // Call the chat method on the server
                test_connection.server.Send("you need to select one!");
            });

            return false;
        }
        else if (docIds.length == 1) {
            docIdsParam = "docId=" + docIds;
            href = window.baseUrl + '/CloudStorage/Download?' + docIdsParam;
        }
        else {
            docIdsParam = jQuery.param(docIds.map(function (value) {
                //var parts = value.match(/[e[B|b]:\/\/[^\/]*\/\d*\/(\d*)/);
                //return { "name": "docIds", "value": parts[1] };
                return { "name": "docIds", "value": value };
            }));
            href = window.baseUrl + '/CloudStorage/DownloadZip?' + docIdsParam;
        }

        $(this).attr('href', href);
        return true;
    });

包装清单:

        <?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Company.CONNECT.Analytics.eFWrapper" version="1.0.0.1" targetFramework="net40" />
  <package id="Company.CONNECT.Analytics.Logging" version="1.0.0.11" targetFramework="net40" />
  <package id="Company.CONNECT.Web" version="1.1.0.12" targetFramework="net40" />
  <package id="Castle.Core" version="2.5.2" targetFramework="net40" />
  <package id="Castle.Core-log4net" version="2.5.2" targetFramework="net40" />
  <package id="Castle.Windsor" version="2.5.4" targetFramework="net40" />
  <package id="Castle.Windsor-log4net" version="2.5.2" targetFramework="net40" />
  <package id="CommonServiceLocator" version="1.0" targetFramework="net40" />
  <package id="EnterpriseLibrary.Common" version="5.0.505.0" targetFramework="net40" />
  <package id="EnterpriseLibrary.WindowsAzure.Configuration" version="5.0.1118.2" targetFramework="net40" />
  <package id="EntityFramework" version="4.1.10331.0" targetFramework="net40" />
  <package id="HtmlAgilityPack" version="1.4.6" targetFramework="net40" />
  <package id="jQuery" version="2.0.2" targetFramework="net40" />
  <package id="jQuery.UI.Combined" version="1.10.3" targetFramework="net40" />
  <package id="jQuery.Validation" version="1.8.0" targetFramework="net40" />
  <package id="jQuery.vsdoc" version="1.5.1" targetFramework="net40" />
  <package id="log4net" version="1.2.10" targetFramework="net40" />
  <package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net40" />
  <package id="Microsoft.AspNet.Providers" version="1.1" targetFramework="net40" />
  <package id="Microsoft.AspNet.Providers.Core" version="1.0" targetFramework="net40" />
  <package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR" version="1.1.2" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.Core" version="1.1.2" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.JS" version="1.1.2" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.Owin" version="1.1.2" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.SystemWeb" version="1.1.2" targetFramework="net40" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.0.0" targetFramework="net40" />
  <package id="Microsoft.AspNet.WebPages" version="2.0.30506.0" targetFramework="net40" />
  <package id="Microsoft.Data.Edm" version="5.5.0" targetFramework="net40" />
  <package id="Microsoft.Data.OData" version="5.5.0" targetFramework="net40" />
  <package id="Microsoft.IdentityModel" version="6.1.7600.16394" targetFramework="net40" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="1.0.1" targetFramework="net40" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
  <package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.1.0" targetFramework="net40" />
  <package id="Modernizr" version="2.6.2" targetFramework="net40" />
  <package id="Newtonsoft.Json" version="4.5.11" targetFramework="net40" />
  <package id="Owin" version="1.0" targetFramework="net40" />
  <package id="Pkcs12ProtectedConfigurationProvider" version="1.0.1" targetFramework="net40" />
  <package id="RequireJS" version="2.1.8" targetFramework="net40" />
  <package id="SevenZipSharp" version="0.64" targetFramework="net40" />
  <package id="SlowCheetah" version="2.5.5" targetFramework="net40" />
  <package id="System.Spatial" version="5.5.0" targetFramework="net40" />
  <package id="System.Web.Providers" version="1.2" targetFramework="net40" />
  <package id="Unity" version="2.1.505.2" targetFramework="net40" />
  <package id="Unity.Interception" version="2.1.505.2" targetFramework="net40" />
  <package id="WebGrease" version="1.1.0" targetFramework="net40" />
  <package id="WindowsAzure.Storage" version="2.0.5.1" targetFramework="net40" />
  <package id="WindowsAzure.Storage" version="2.0.6.0" targetFramework="net40" />
</packages>


推荐答案

事实证明,有2个Web角色实例正在运行我的Windows Azure配置。当有多个Azure实例在运行时,需要使用背板,因为我们无法控制Azure负载均衡器选择的实例。这就是为什么从服务器发送回客户端的消息在50%的时间内都失败了。

It turns out there are 2 Web Role instances running in my Windows Azure configuration. When there are multiple Azure instances running, a "backplane" needs to be used since we have no control over which instance the Azure Load Balancer chooses. This is why the messages sent back from the server to client were failing 50% of the time.

http://www.asp.net/signalr/overview/performance-and-scaling/scaleout-in-signalr

这篇关于从服务器到客户端方法的SignalR Hub(在云中)回调的间歇性问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆