Ядро ASP.NET SignalR - согласование концентратора - Err_Connection_Refused - PullRequest
0 голосов
/ 10 апреля 2019

Я впервые работаю с SignalR и пытаюсь подключиться к хабу из Angular.Я пытаюсь реализовать то же самое в этой ССЫЛКЕ

Я не уверен, откуда происходят эти переговоры

ОПЦИИ http://localhost:5001/messageHub/negotiate net :: ERR_CONNECTION_REFUSED

Вот мой код.

public startConnection = () => {
this.hubConnection = new signalR.HubConnectionBuilder()
  .withUrl('http://localhost:5001/messageHub')
  .build();

this.hubConnection
  .start()
  .then(() => alert('Connection started'))
  .catch(err => alert('Error while starting SignalR connection: ' + err));
}

Вот appsettings.Development.json

 "Logging": {
"LogLevel": {
  "Default": "Debug",
  "System": "Information",
  "Microsoft": "Information"
}},
"SignalR": {
"messageHub": "http://localhost:5001/messageHub"
  },
"Api": {
"GenerateTokenUrl": "http://localhost:5000/api/Values"
 }

Это дает мне эту ошибку в инструментах Chrome Dev messageHub Negotiate

1 Ответ

0 голосов
/ 12 мая 2019

Чтобы запустить signalR в ядре asp.net, вы должны сконфигурировать эти шаги следующим образом

в вашем машинописном коде

this._hubConnection = new HubConnectionBuilder()
      .withUrl("/signalr")
      .configureLogging(LogLevel.Error)
      .build();

this._hubConnection.start().catch(err => console.error(err.toString()));

Startup.cs

services.AddSignalR();
app.UseSignalR(routes =>
{
  routes.MapHub<ConnectionHub>("/connectionHub");
});

И твой хаб класс

 public class ConnectionHub : Hub
    {
        public async Task Send(string userId)
        {
            var message = $"Send message to you with user id {userId}";
            await Clients.Client(userId).SendAsync("ReceiveMessage", message);
        }

        public string GetConnectionId()
        {
            return Context.ConnectionId;
        }
    }
...