I have the following JS code
var chat = $.connection.MyHub;
chat.client.initChart = function (data) {
... do stuff ...
}
and this hub code
public class MyHub : Hub
{
public override Task OnConnected()
{
using (var conn = new SqlConnection(ConnectionString))
{
conn.Open();
//Using Dapper
var data = conn.Query("SELECT data FROM Sql").ToList();
return Clients.Caller.initChart(data);
}
}
}
this works perfectly on my machine (Win7Pro, IIS 7), however, when I deploy it to our server (Win2008R2, iis7) it doesn’t call the initChart function. I’ve got VS installed on the server, and when I debug the process, the OnConnected event is called and completes successfully, but nothing happens on the client. There are no JS errors or server side errors occurring that I can see.
Just to confuse things further, I have another function declared on the client that is called by an NServiceBus handler, this function gets called every time, I put a browser breakpoint in there & I can see it being called.
Checking the signalR logs on my machine it uses SSE, but on the server it falls back to long polling.
UPDATE: Just realized the server is sitting behind Akamai’s DSD, if I don’t go through this, it works, but I can’t see why it makes a difference.
2nd Update:
Here are the different response headers for the connect?transport=serverSentEvents&connectionId=9fce5552-4c2e-4739-93ea-501dda0a0654&connectionData=%5B%7B%22name%22%3A%22navigationtiminghub%22%7D%5D&tid=9 HTTP/1.1 call
first, the request when I call directly to origin:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: text/event-stream
Expires: -1
Server: Microsoft-IIS/7.5
Date: Mon, 07 Jan 2013 01:08:26 GMT
and this is Akamai’s response. Note, according to wireshark, the response from our server to Akamai is identical to the above response
HTTP/1.1 200 OK
Content-Type: text/event-stream
Server: Microsoft-IIS/7.5
Expires: Mon, 07 Jan 2013 01:07:23 GMT
Cache-Control: max-age=0, no-cache, no-store
Pragma: no-cache
Date: Mon, 07 Jan 2013 01:07:23 GMT
Content-Length: 486
Connection: keep-alive
Also in the first one, the connection stays open (as it should) and in the second it closes.
UPDATE 3: This is purely an Akamai problem, we just switched to Edgecast & they respond to the SSE connect correctly.
You can see this in the headers above, as you have a
Content-Lengthheader and you are also missing theTransfer-Encodingheader in your response.You can’t enable buffering yourself but you can get their professional services team to do it for you.
This seems to fix the Server Sent events for Chrome, but not the Forever Frame for IE9.
With the Forever Frame this appears to be a compression issue. The
Transfer-Encoding: chunkedheader is restored if you nuke theAccept-Encodingheader from your request. Then IE works nicely. An exclusion for the edge’s gzip feature is required for the hub url.