2
votes

I've tried to setup the following configuration with SQL Server and SignalR

http://www.asp.net/signalr/overview/performance/scaleout-with-sql-server

Everything seems to be setup correctly, if I profile SQL server I can see SignalR making calls to the DB, but when I call the hub to send a message to all the clients connected, the message is never sent to the connected browsers.

any idea what could be the problem?

1
Have you checked the network traffic to make sure the messages are not making it back to the browser? It is possible you have a method signature mismatch (casing) so that the handler isn't getting wired up correctly.Jim Wooley
So, everything was working fine, but the way I did setup the dependency injection was wrong. IHubContext must be recreate at every request, while I was using a Singleton.smnbss
I have the same issue when I deploy-- Exception: System.InvalidOperationException Message: Nullable object must have a value. StackTrace: at Microsoft.AspNet.SignalR.SqlServer.SqlReceiver.Receive(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) ...Elan Hasson

1 Answers

3
votes

Thank you @smnbss, you just saved my life with your comment inside your question. Just to make it clear for everyone in the future with the same problem, here is the wrong implementation: I was getting the context only once like:

public class SyncService : ISyncService
{
    private IHubContext StatusChangeHub { get; set; }

    public GatewaySyncService()
    {
        StatusChangeHub = GlobalHost.ConnectionManager.GetHubContext<Hub>();
    } 

    public void SyncStatusChange(Status newStatus)
    {
        StatusChangeHub.Clients.All.onStatusChange(newStatus);      
    }
}

But somehow this only work while not using a backplane. And the correct implementation: you need to get the context everytime you want to send a message:

public class SyncService : ISyncService
{
    public void SyncStatusChange(Status newStatus)
    {
        var context = GlobalHost.ConnectionManager.GetHubContext<Hub>();

        context.Clients.All.onStatusChange(newStatus);      
    }
}