c# - Call SignalR client from Web API Controller -


following scenario: i've got asp.net web api running signalr hub, serving spa. signalr hub used communicate several c# signalr clients. want retrieve data specific client , return data web api controller web client. please see sample below:

    public async task<ihttpactionresult> get()     {         microsoft.aspnet.signalr.globalhost.connectionmanager.gethubcontext<hubs.confighub>().clients.client("someconnectionid").getdata();         // signalr client calling callback method on signalr hub hosted in web api         // return data;      } 

is there way how can achieve this?

you can´t retrieve client data server hub. that´s signalr missing feature.

the server can invoke commands on client can´t await response, clients.client("someconnectionid").getdata() won´t ever return anything. clients able that.

there not easy path it. solve situation:

public async task<ihttpactionresult> get() {     microsoft.aspnet.signalr.globalhost.connectionmanager         .gethubcontext<hubs.confighub>()         .clients.client("someconnectionid")         .pleasesendyourdatatothehub();       // don´t return , don´t await results on web client.       // client needs 200 (ok) response sure request       // sent , going on.  } 

clients "listen" command (pleasesendyourdatatothehub) , call corresponding method in hub.

in hub have method like:

public void onclientdata(datatype data) {     // todo find out web client connection id      // send data web client     clients.client("webclientconnectionid")         .datafromclient(clientid, data); } 

then, in web client, listen proxy event like:

proxy.on('datafromclient', function(clientid, data) {     // data }); 

Comments