Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I call a dynamically selected SignalR client method from an IHubContext?

Tags:

signalr

Is there any way to do something like this in SignalR:

public void CallClientMethod(string methodName, MyObject data)
{
    var ctx = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
    ctx.Clients.All.methodName(data);

    // or alternatively
    ctx.Clients.All.CallClientMethod(methodName, data);
}

The above example illustrates the intent, rather than the actual mechanism - I want to determine the method to call at runtime, rather than compile time.

like image 456
jimmy_terra Avatar asked Oct 28 '13 10:10

jimmy_terra


1 Answers

You can do this:

public void CallClientMethod(string methodName, MyObject data)
{
    var ctx = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
    IClientProxy proxy = ctx.Clients.All;

    proxy.Invoke(methodName, data);
}
like image 93
davidfowl Avatar answered Sep 17 '22 17:09

davidfowl