简体   繁体   中英

SignalR failing at the final proxy call

I have a Web Api Service that sends signalR notifications to a proxy I have running on an MVC website that sits on the same box. After lots of tweaks I have got the web service talking to the hub on the website, confirmed by debug logging.

On the website side, it seems like everything is being called fine and it seems to have a reference to my client browser that is calling the website. Below I'll paste the Hub class and the debug log output to prove this.

The final line is

Clients.Client(conn).addNotification(notification);

which I assume then looks for a JavaScript method matching that signature. Of which I have one. Below is the method in my JS files.

 notifyProxy.client.addNotification = function (notification) {
            $notificationTableBody.prepend(rowTemplate.supplant(formatNotification(notification)));
        };

However setting a break point on this (Using chrome developer tools), the method never gets called. No errors are reported from the MVC website and none in the developer tools console, though I don't know if SignalR writes errors elsewhere.

The only other thing of note is in the JS file I have a line

$.connection.hub.start().done(init);

Which gets called when I set a breakpoint in Chrome developer tools. However the init() method never gets called. Does this mean potentially the hub.start() method is failing? If so how can I find out why?

What is going wrong? I am quite new to signalR so am losing my mind!

Code for my hub class and debug output below

public void PushNotification(EventNotification notification, List<string> users)
        {
            _logger.WriteDebug("Entered push notification");
            if (notification.FriendlyText.Length > 1000)
                notification.FriendlyText = notification.FriendlyText.Substring(0, 1000) + "...";
            if (users.Contains("*") && users.Count > 1)
            {
                users.RemoveAll(u => !u.Equals("*"));
            }
            foreach (var userName in users)
            {
                _logger.WriteDebug("Push notification for " + userName); 
                UserConnectionInformation user = null;
                if (UserInformation.TryGetValue(userName.ToUpperInvariant(), out user))
                {
                    _logger.WriteDebug("Adding " + notification.FriendlyText + ", " + user.ConnectionIds.Count + " connections"); 
                    user.Notifications.Add(notification);
                    lock (user.ConnectionIds)
                    {
                        foreach (var conn in user.ConnectionIds)
                        {
                            _logger.WriteDebug("Is Client null - {0}", Clients.Client(conn) == null);
                            _logger.WriteDebug("Conn {0}", conn);
                            var proxy = Clients.Client(conn) as ConnectionIdProxy;
                            _logger.WriteDebug("proxy {0}", proxy.ToString());
                            Clients.Client(conn).addNotification(notification);
                            _logger.WriteDebug("Added notification ");
                        }
                    }
                }
            }
        }

11-12-2015 12:19:43,808 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Entered push notification
11-12-2015 12:19:43,808 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Push notification for kerslaj1
11-12-2015 12:19:43,808 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Push notification for UK\kerslaj1
11-12-2015 12:19:43,808 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Adding Job 'testrose45job-11dec15121944' ('ROSE-0000045') cancellation has been requested by 'UK\kerslaj1' on 'seflexpool3'., 1 connections
11-12-2015 12:19:43,808 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Is Client null - False
11-12-2015 12:19:43,808 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Conn 3d008947-0d96-4965-bb01-dfd1517c24a5
11-12-2015 12:19:43,808 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - proxy Microsoft.AspNet.SignalR.Hubs.ConnectionIdProxy
11-12-2015 12:19:44,803 [UK\kerslaj1][20] DEBUG Centrica.CE.SEFlex.Common.Logging.ConsoleLogger - Added notification 

See if you can get errors back from the proxy:

$.connection.hub.error(function (error) {
    console.log('SignalR error: ' + error)
});

Also you might need to enable client side logging before starting the connection:

// enable client side logging
$.connection.hub.logging = true;
$.connection.hub.start()
    .done(function(){ console.log('Now connected, connection ID=' + $.connection.hub.id); })
    .fail(function(){ console.log('Could not Connect!'); });
});

Let's see if we get any further from there and if the start of the hub connection is the actual problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM