Call SignalR Hub from Backend Business Layer

人盡茶涼 提交于 2019-12-10 16:36:27

问题


I have an MVC website sitting onto of some fairly hefty business objects. My MVC Controllers call Manager objects which conducts and delegates work off to other sets of objects.

Basically the code is deep server side, while a Hub in a way is just like a Controller in that it is fairly close to the client side.

Is there a way to execute SignalR methods based on a reference to the Hub passed to these Manager objects?


回答1:


If your MVC and SignalR services are running on the same process, you can call GlobalHost.ConnectionManager.GetHubContext("MyHub");

It they are on separate processes, then you need to create a SignalR client in your MVC app




回答2:


Well all of the clients will connect to your web app and persist the connections there. From a separate back end program you can just call a web service in your web app and that web service can post the message on the same SignalR hub in your web project. Your back end app can't connect to the SignalR hub directly. It all flows through a single point, being your web app.

If you are just talking about a shared class library in the same web app, you should be able to pass the hub object to the other class as the other person answered: GlobalHost.ConnectionManager.GetHubContext("MyHub");



来源:https://stackoverflow.com/questions/18126103/call-signalr-hub-from-backend-business-layer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!