signalr core - how to call hub method from client


February 2019


3 time


I'm adding SignalR to my app. I can send messages from server to client, but can't call hub methods from client. Here's my hub interface:

    public interface IGeneralHub
    Task BroadcastMessage(HubMessage msg); //string type, string payload);
    Task JoinHub(List<int> ids);

and hub client:

    public class AuctionHub : Hub<IGeneralHub>
    public void Broadcast(HubMessage msg)
    public void JoinHub(List<int> ids)
        foreach (var id in ids.Distinct())
            Groups.AddToGroupAsync(Context.ConnectionId, id.ToString());

And client side:

this.hubConnections = new signalR.HubConnectionBuilder()
                    .then(() => console.log('Connection started'))
                    .catch(err => console.log('Error while starting connection: ' + err));
                this.hubConnections.invoke('joinGroup', JSON.parse(localStorage.getItem('ws-document')));

I receive messages, but joinGroup is never called. What am I doing wrong?

0 answers