Я пытаюсь инициализировать SignalR в моем приложении Angular 6 и вызываю отдельный веб-интерфейс ASP.Net для хабов.
CORS настроен правильно и разрешает вызовы, однако я застрял на этой ошибке:
Debug: Sending negotiation request: http://devapi.mywebapi.com/srtest/negotiate
http://devapi.mywebapi.com/srtest/negotiate 404 (Not Found)
Я установил 1.0 библиотеки NPM @ aspnet / signalr typcript и инициализирую ее так:
import { Component, OnInit } from "@angular/core";
import { HubConnection, HubConnectionBuilder, LogLevel } from '@aspnet/signalr';
@Component({
selector: "test",
templateUrl: "test.component.html"
})
export class TestComponent implements OnInit {
private hubConnection: HubConnection;
constructor() { }
ngOnInit() {
this.hubConnection = new HubConnectionBuilder()
.withUrl("http://devapi.mywebapi.com/srtest")
.configureLogging(LogLevel.Debug)
.build();
this.hubConnection
.start()
.then(() => console.log('Connection started!'))
.catch(err => console.log('Error while establishing connection :('));
}
}
Мой класс запуска определен как:
using Owin;
using Microsoft.Owin;
[assembly: OwinStartup(typeof(Api.Controllers.SignalR.Startup))]
namespace Api.Controllers.SignalR
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
// Any connection or hub wire up and configuration should go here
app.MapSignalR();
}
}
}
и мой класс-концентратор:
using Microsoft.AspNet.SignalR;
using System.Threading.Tasks;
using System.Web.Http;
namespace Api.Controllers.SignalR
{
public class SRTestHub : Hub
{
public void SendTest(string message)
{
var context = GlobalHost.ConnectionManager.GetHubContext<SRTestHub>();
context.Clients.All.receiveMessage(message);
}
}
}
Что я делаю не так?