Reputation: 972
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
[12:14:22 GMT-0400 (Eastern Daylight Time)] SignalR: Client subscribed to hub 'centralhub'
[12:14:22 GMT-0400 (Eastern Daylight Time)] SignalR: Negotiating with '/signalr/negotiate?connectionData=%5B%7B%22name%22%3A%22centralhub%22%7D%5D&clientProtocol=1.3'. jquery.signalR-2.0.3.js:76
Google Console Output from Visual Studio 2013
[12:17:56 GMT-0400 (Eastern Daylight Time)] SignalR: Client subscribed to hub 'centralhub'.jquery.signalR-2.0.3.js:76
[12:17:56 GMT-0400 (Eastern Daylight Time)] SignalR: Negotiating with '/signalr/negotiate?connectionData=%5B%7B%22name%22%3A%22centralhub%22%7D%5D&clientProtocol=1.3'. jquery.signalR-2.0.3.js:76
[12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Attempting to connect to SSE endpoint 'http://localhost:32568/signalr/connect?transport=serverSentEvents&connectio…kMTNQps1lto&connectionData=%5B%7B%22name%22%3A%22centralhub%22%7D%5D&tid=3'. jquery.signalR-2.0.3.js:76
[12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: EventSource connected. jquery.signalR-2.0.3.js:76
[12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332 and a connection lost timeout of 20000. jquery.signalR-2.0.3.js:76
[12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Invoking centralhub.InitialMessage jquery.signalR-2.0.3.js:76
[12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Invoking centralhub.Test jquery.signalR-2.0.3.js:76
[12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Triggering client hub event 'logEvent' on hub 'CentralHub'. jquery.signalR-2.0.3.js:76
[12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Triggering client hub event 'test' on hub 'CentralHub'. jquery.signalR-2.0.3.js:76
[12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Invoked centralhub.Test jquery.signalR-2.0.3.js:76
[12:17:57 GMT-0400 (Eastern Daylight Time)] SignalR: Invoked centralhub.InitialMessage
Upvotes: 4
Views: 1422
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
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.
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
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