Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无论如何,要将消息从集线器类发布到另一个集线器';s javascript处理程序函数_C#_Asp.net_Signalr_Signalr Hub - Fatal编程技术网

C# 无论如何,要将消息从集线器类发布到另一个集线器';s javascript处理程序函数

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类内部调用它的。这可能吗?如果两个集

我有两个轮毂类:hubA和hubB

在hubA中,我有一个执行任务的函数:

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); 
}