如果两个毂在同一个应用程序托管,你就应该能够使用:
GlobalHost.ConnectionManager.GetHubContext<HubB>()
现在的诀窍是,你似乎想将消息发送到特定的客户端上HUBB和问题HubA的Context.ConnectionId
将不会是HubB的相同ID。因此,您需要做的是在HubA和HubB中将某种类型的ConnectionId映射到逻辑上的某种用户。然后,当您需要“弥合差距”时,您通过HubA的ConnectionId查找来自HubA的逻辑用户,然后查找HubB的ConnectionId。在这一点你的代码可能看起来像这样:
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);
}
你能解释一下好一点吗?也许再添加一些代码? – JotaBe