带有 MVC 5 的 Angular 6 Signalr

编程入门 行业动态 更新时间:2024-10-17 23:35:40
本文介绍了带有 MVC 5 的 Angular 6 Signalr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-22 16:33:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026973.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MVC   Angular   Signalr

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!