SignalR calling client method from outside hub using GlobalHost.ConnectionManager.GetHubContext doesn't work. But calling from within the hub does

后端 未结 2 821
死守一世寂寞
死守一世寂寞 2020-12-04 15:39

I\'m trying to call a client method from within a .net Web API controller action.

Can I do this?

The only post I can find that comes close to what I am looki

2条回答
  •  渐次进展
    2020-12-04 16:23

    I had the same issue, and it is related to IoC (with whatever such as ninject or castle). If you set the global dependency resolver to your IoC manager, it will also replace the SignalR inner pipeline resolution. This makes your SingleTon client hub, not work correctly.

    I solved it by only having the Server Hubs being IoC-ed The code below requires SignalHubActivator (you can find it on the internet)

    Now, GlobalHost.ConnectionManager.GetHubContext will return the single instance AND client methods will be called correctly again!

     //configuration.Resolver = signalrDependency ; dont, this will cause GlobalHost.ConnectionManager to be intercepted by Castle
    
    
     configuration.Resolver.Register(typeof(IHubActivator),
                                          () => new SignalHubActivator(container));
    

提交回复
热议问题