问题描述
我在 mvc 5 中的当前项目中使用 angular 6,所有其他事情都运行良好,我在实现 SignalR 时面临的唯一问题,这是我的 signalr.service.ts 代码:
I am using angular 6 with my current project which is in mvc 5 , all other things are working perfect, the only problem i am facing in implementing SignalR, this is my signalr.service.ts code:
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 可以使用 angular 6 Signalr 吗?因为根据我的知识和搜索,我发现 angular 6 signalr 只能与 Core 一起使用?
Btw; angular 6 Signalr is possible with MVC5? because as per my knowledge and search i have found that angular 6 signalr can be used only with Core?
推荐答案
如果您希望使用 MVc5 解决方案来使用 SignalR,那么您需要将 jQuery.signalR 模块与您的 angular 客户端一起使用,而不是 @aspnet.信号R.
if you looking to user signalR with a MVc5 solution, then you'll need to use the jQuery.signalR module with your angular client instead of the @aspnet.SignalR.
这篇关于带有 MVC 5 的 Angular 6 Signalr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!