In my current setup, i have an ASP.NET 5 vNext project running. I have setup SignalR Server 3.0.0-rc1-final and i am able to connect to my hub through my webinterface:

var visitorHub = $.connection.visitorsHub;

visitorHub.client.visitorEvent = function (message) {
   $("#visitorinfo").append("<li>" + message + "</li>");
};

$.connection.hub.start().done(function () {
   visitorHub.invoke("listenToEvents", "TestID");
});

So we are listening on visitorEvent from the hub and visitorEvent is called when listenToEvents is invoked.

My challenge come now, that i'm trying to notify from within the ASP.NET application. Using the build in IoC an SqlDependency is used to listen to events in the SQL server. Again this is working as intended, but when i'm trying to invoke the hub through it's HubContext nothing happens.

I have injected the IConnectionManager and able to get hold of my HubContext using:

var context = this.manager.GetHubContext<VisitorsHub>();

but when i do the following:

context.Clients.All.visitorEvent("2");

nothing happens.

I'm not sure why nothing happens and how i'm going to debug this?

My VisitorHub code is:

public class VisitorsHub : Hub
{
    public async Task ListenToEvents(string visitorId)
    {
        this.NotifyVisitorListeners();
    }

    public void NotifyVisitorListeners()
    {
        this.Clients.All.visitorEvent("Event");
    }
}

Related posts

Recent Viewed