C# 无论如何,要将消息从集线器类发布到另一个集线器';s javascript处理程序函数
我有两个轮毂类:hubA和hubB 在hubA中,我有一个执行任务的函数:C# 无论如何,要将消息从集线器类发布到另一个集线器';s javascript处理程序函数,c#,asp.net,signalr,signalr-hub,C#,Asp.net,Signalr,Signalr Hub,我有两个轮毂类:hubA和hubB 在hubA中,我有一个执行任务的函数: public void doSomething(string test){ Clients[Context.ConnectionId].messageHandler(test); } 我不希望此函数发回hubA.messageHandler=function(){…}我希望能够将消息发回hubB.messageHandler=function(){…},但我是从hubAhub类内部调用它的。这可能吗?如果两个集
public void doSomething(string test){
Clients[Context.ConnectionId].messageHandler(test);
}
我不希望此函数发回
hubA.messageHandler=function(){…}
我希望能够将消息发回hubB.messageHandler=function(){…}
,但我是从hubA
hub类内部调用它的。这可能吗?如果两个集线器都托管在同一个应用程序中,您应该可以使用:
GlobalHost.ConnectionManager.GetHubContext<HubB>()
你能解释清楚一点吗?也许可以添加更多的代码?
public void DoSomething(string test)
{
// Get HubB's ConnectionId given HubA's ConnectionId (implementation left to you)
string hubBConnectionId = MapHubAConnectionIdToHubBConnectionId(Context.ConnectionId);
// Get the context for HubB
var hubBContext = GlobalHost.ConnectionManager.GetHubContext<HubB>();
// Invoke the method for just the current caller on HubB
hubBContext.Clients[hubBConnectionId].messageHandler(test);
}