簡體   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