asp.net основной сигнал R 2.2 вход - PullRequest
0 голосов
/ 30 января 2019

Я работаю над приложением ASP.NET Core 2.2 SignalR.

Сервер уведомляет клиента (onFreshData () ниже).Мне бы хотелось, чтобы метод, вызываемый на клиенте, вызывал другой метод на сервере.

Это кажется неподдерживаемым в том смысле, что если серверный код вызывается правильно, клиентский код (машинопись) получает ошибку.

Этот метод вызывается с сервера:

  onFreshData = (data: any): void => {
    const received = `Données reçues: ${data}`;
    this.messages.push(received);
    const dashboardData = DashboardDataProxy.Parse(data);

    // Build a ticks array
    const almostTicks: number[] = [];
    const alerts = dashboardData.alerts;
    alerts.forEach(a => almostTicks.push(moment.utc(a.AlertDateTime).valueOf() * 10000));
    // Call the server method for formatting
    this.notificationService.formatDateTimeArrayOnServer(almostTicks, 'fr-FR', moment().utcOffset())
      .then(() => { this.chartService.updateAlertHistory(alerts); });
    ;
  }

Ниже приведен код клиента, который вызывает сервер:

public async formatDateTimeArrayOnServer(almostUtcTicks: number[], currentCulture: string, utcOffset: number) {
    if (this.hubConnection) {
      let result = await this.hubConnection.invoke('FormatDateTimeArray', almostUtcTicks, currentCulture, utcOffset);
      return result;
    }

  }

Значение результата вотладчик chrome:

"результат не определен" "ReferenceError: результат не определен в eval (eval в push ../ src / app / services / messages.service.ts.NotificationService.formatDateTimeArrayOnServer (https://localhost:44338/main.js:5116:12),: 1: 1) в NotificationService.push ../ src / app / services / messages.service.ts.NotificationService.formatDateTimeArrayOnServer (https://localhost:44338/main.js:5116:12) в HubConnection.NotificationComponata.on1020 *https://localhost:44338/src-app-components-dashboard-dashboard-module.js:448:39) в https://localhost:44338/vendor.js:139594:53 в Array.forEach () в HubConnection.push ../ node_modules/@aspnet/signalr/dist/esm/HubConnection.js.HubConnection.invokeClientMethod (https://localhost:44338/vendor.js:139594:21)в ХуbConnection.push ../ node_modules/@aspnet/signalr/dist/esm/HubConnection.js.HubConnection.processIncomingData (https://localhost:44338/vendor.js:139489:30) в WebSocketTransport.HubConnection.connection.onreceive (https://localhost:44338/vendor.js:139225:68) в WebSocket.we.onmessage [as __zone_symbol__ON_PROPERTYmessage] (https://localhost:44338/vendor.js:140902:43) на WebSocket.wrapFn (https://localhost:44338/polyfills.js:3677:39)"

...