【发布时间】:2018-09-18 12:21:30
【问题描述】:
我在 mvc 5 中的当前项目中使用 angular 6,所有其他事情都运行良好,我在实现 SignalR 时面临的唯一问题,这是我的 signalr.service.ts 代码:
export class SignalRService {
dataReceived = new EventEmitter<myData>();
connectionEstablished = new EventEmitter<Boolean>();
private connectionIsEstablished = false;
private _hubConnection: HubConnection;
constructor() {
this.createConnection();
this.registerOnServerEvents();
this.startConnection();
}
private createConnection() {
this._hubConnection = new HubConnectionBuilder()
.withUrl(window.location.href+'testHub')
.build();
}
private startConnection(): void {
this._hubConnection
.start()
.then(() => {
this.connectionIsEstablished = true;
console.log('Hub connection started');
this.connectionEstablished.emit(true);
})
.catch(err => {
console.log('Error while establishing connection, retrying...');
//setTimeout(this.startConnection(), 5000);
});
}
private registerOnServerEvents(): void {
this._hubConnection.on('sendProgressTrackerAlert', (data: any) => {
this.dataReceived.emit(data);
});
}
}
但它给了我这个错误:
Utils.js:148 Error: Failed to complete negotiation with the server: Error: Not Found
push../node_modules/@aspnet/signalr/dist/esm/Utils.js.ConsoleLogger.log
@ Utils.js:148 14:55:10.842 Utils.js:148 Error: Failed to start the
connection: Error: Not Found
顺便说一句; MVC5可以使用角度6 Signalr吗?因为根据我的知识和搜索,我发现 Angular 6 信号器只能与 Core 一起使用?
【问题讨论】:
标签: asp.net-mvc-5 signalr angular6