【问题标题】:Angular 6 Signalr with MVC 5带有 MVC 5 的 Angular 6 Signalr
【发布时间】: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


    【解决方案1】:

    如果您希望使用 MVc5 解决方案来使用 signalR,那么您需要将 jQuery.signalR 模块与您的 Angular 客户端一起使用,而不是 @aspnet.SignalR。

    【讨论】:

      猜你喜欢
      • 2015-04-03
      • 2014-09-04
      • 1970-01-01
      • 2015-01-07
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2021-11-06
      相关资源
      最近更新 更多