繁体   English   中英

来自客户端的集线器方法未在ASP.NET Core SignalR中调用

[英]Hub method from client is not invoking in ASP.NET Core SignalR

我正在将SignalR添加到我的应用中。 我可以从服务器向客户端发送消息,但是不能从客户端调用集线器方法。 这是我的集线器界面:

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

和中心客户端:

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

和客户端:

this.hubConnections = new signalR.HubConnectionBuilder()
                    .withUrl(`${environment.hubHost}/document/`)
                    .build();

this.hubConnections.start()
                    .then(() => console.log('Connection started'))
                    .catch(err => console.log('Error while starting connection: ' + err));

this.hubConnections.invoke('joinGroup', JSON.parse(localStorage.getItem('ws-document')));

我收到消息,但从未调用joinGroup 我究竟做错了什么?

我收到消息,但从未调用joinGroup。 我究竟做错了什么?

这是因为AuctionHub类中没有JoinGroup方法。 它应该JoinHub ,如下所示:

this.hubConnections.invoke('joinHub', JSON.parse(localStorage.getItem('ws-document')));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM