Question

I'm wondering if it's possible to Cast the result of var hub = GlobalHost.ConnectionManager.GetHubContext<ChatHub>(); To my actual ChatHub class. Because GlobalHost.ConnectionManager.GetHubContext<ChatHub>() as ChatHub fails

On my ChatHub class I have a method UpdateTime():

public void SendTimeUpdate(DateTime time, string auth)
{
    Clients.All.UpdateTime(time, auth);
}

And I want to call it from my other class. Since I can't cast to ChatHub and invoke the SendUpdate I have to go:

GlobalHost.ConnectionManager.GetHubContext<ChatHub>().Clients.All.UpdateTime(time, auth);

But if I go this road, the method SendTimeUpdate isn't added in the proxy script /signalr/hubs

Is there a solution for this problem? I want to get the typed Hub instance and not call stuff directly on the Clients property of the IHubContext.

Was it helpful?

Solution

No you cannot cast the result of ....GetHubContext<.... to your hub class. Sorry :(.

The GetHubContext approach returns an IHubContext when a Hub is only an IHub.

If you'd like to centralize the logic just make a method that you can call into from your hub and from your external service.

OTHER TIPS

Couldn't your class just create a connection to your hub and call the method that way?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top