Angular 6 Signalr with MVC 5

强颜欢笑 提交于 2020-02-07 03:46:06

问题


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);
    });
}

}

But it is giving me this error:

     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

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? Shillong


回答1:


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.



来源:https://stackoverflow.com/questions/52386494/angular-6-signalr-with-mvc-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!