Kelso Sharp
Kelso Sharp

Reputation: 972

Signalr client methods not called consistently when deployed to IIS

I am really stumped on this one, I have a page that I am using to collect data on what methods are being called in my web application. When I run my application from visual studio, there is no problem, everything works great, all my server and client methods function as expected.

However, when I deploy this application to my webserver running IIS 7.5 on windows server 2008, R2 SP1 my client side methods do not consistently fire, everything looks like its running fine. but the triggering client event never happens.

Client Side Javascript:

var nlog = $.connection.centralHub;
$.connection.hub.logging = true;

$(function () {
    var logTable = $("#logTable");

    nlog.client.logevent = function (datetime, siteName, clientConId, logLevel, message, stack, eMessage) {
    var tr = $("<tr>");
        tr.append($("<td>").text(datetime));
        tr.append($("<td>").text(siteName));
        tr.append($("<td>").text(clientConId));
        tr.append($("<td>").text(logLevel));
        tr.append($("<td style='white-space: pre;'>").text(message));
        tr.append($("<td>").text(stack));
        tr.append($("<td>").text(eMessage));
        logTable.append(tr);
    };
    nlog.client.test = function() {
        $("#test").text("spit out a test");
    }
    $.connection.hub.start().done(function () {
        nlog.server.initialMessage();
        nlog.server.test();
    }, 5000);
});

Server Hub methods:

Hub Method: CentralHub

public void InitialMessage()
    {
        string connId = Context.ConnectionId;
        _clientTracker.InitalMessage(connId);
    } 

internal void InitalMessage(string connId)
    {

        Clients.All.logEvent(
            DateTime.Now.ToString("F"),
            "Harper Woods",
            connId,
            "info",
            "Hub Started",
            "No Message",
            "No Message");
    }

Google Console output from my IIS webserver

Google Console Output from Visual Studio 2013

Upvotes: 4

Views: 1422

Answers (3)

dotnetspark
dotnetspark

Reputation: 581

At first sight, within your done() you are calling a Test method from the server which doesn’t exist or at least is missing. Removing this line could make it work.

Upvotes: 0

Sobhan
Sobhan

Reputation: 1061

I had this same exact issue. My SignalR Application would work perfectly in Visual Studio or Windows Local OS IIS. But when I deployed it to IIS 7.5 on Windows Server 2008 R2, the client methods wouldn't get invoked consistently. That was all because my application pool in deployment IIS server, had 10 working processors (i.e. Web Garden). This post helped me realize this and when I set the working processors to 1, It did the trick. Apparently this is by design.

From @AlexanderKöplinger:

This is by design. The two worker processes don't share state and clients will be distributed between them on a round-robin basis, which means 50% will connect to process A and 50% to process B. As the underlying SignalR message bus is in-memory by default, process A doesn't see messages from process B.

I'll set the working processor to 1 for now, but I'll try to find a way to make Web Garden work with SignalR.

Update:

Setting working processors to 1 is not good in regards of scaling. The SignalR team did provide us a way to make Web Garden work with SignalR and it's explained here. You have 3 methods to choose from and I decided to use the SQL server approach. The setup went smooth and easy and now SignalR is using SQL server as a backplane to share messages between different working processors.

Upvotes: 0

Kelso Sharp
Kelso Sharp

Reputation: 972

Ok, I finally was able to find a bit of information on what is going on here. It is where you set the dependency injection resolver for signalr, this MUST be done in the Application_Start() method of the Global.asax, you cannot rely on ninject web bootstrapper, and you cannot put it in the owin startup class like the example on ASP.NET site. It will not function predictably it will work sometimes, but you will miss messages.

Upvotes: 0

Related Questions