Asp. Net MVC WebAPI и Angular 7 в конфигурации singalR - PullRequest
0 голосов
/ 23 марта 2020

Я пытаюсь использовать Angular 7 и Asp. Net MVC WebAPI для создания веб-сайта аукциона.

В то же время различные пользователи могут делать ставки на одном аукционе и на самом низком Цена видна всем пользователям. Кроме того, аукционы запланированы многими продавцами одновременно. Пожалуйста, предложите, как реализовать такой сайт.

В настоящее время я пытаюсь с SignalR, и я получаю следующие ошибки:

В Angular Код:

import { Component } from '@angular/core';
import { HubConnection } from '@aspnet/signalr';
import * as signalR from '@aspnet/signalr';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  private hubConnection: HubConnection;

  title = 'SingalR';

  public ngOnInit() {

    this.hubConnection = new signalR.HubConnectionBuilder().
      configureLogging(signalR.LogLevel.Debug).
      withUrl("http://localhost:58192/signalr", {
        skipNegotiation: true,
        transport: signalR.HttpTransportType.WebSockets
      }).build();

    this.hubConnection.start().
      then(function () { console.log('Connected!'); }).
      catch(function (err) { return console.error(err); });

  }
}

В Visual Studio 2015:
Файл Startup.cs

using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(SingalR_API.Startup))]
[assembly: OwinStartupAttribute(typeof(SingalR_API.Startup))]

namespace SingalR_API
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.MapSignalR("/signalr", new Microsoft.AspNet.SignalR.HubConfiguration());
            // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
        }
    }
}

Файл ServiceStatusHub.cs :

using Microsoft.AspNet.SignalR;
using System.Collections.Generic;

namespace SingalR_API.Controllers
{
    public class ServiceStatusHub : Hub
    {
        private static IHubContext hubContext =
        GlobalHost.ConnectionManager.GetHubContext<ServiceStatusHub>();

        public static void GetStatus(string message)
        {
            hubContext.Clients.All.acknowledgeMessage(message);
        }


        public IEnumerable<string> Get()
        {
            // Query service to check status
            ServiceStatusHub.GetStatus("Please check status of the LDAP!");
            return new string[] { "val1", "val2" };
        }
    }
}

Файл WebApiConfig.cs :

using System.Web.Http;
using System.Web.Http.Cors;

namespace SingalR_API
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {

            config.EnableCors(new EnableCorsAttribute("*", "*", "*"));

            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );
        }
    }
}

Ошибка:

Ошибка

Utils.js:203 [2020-03-23T22:26:24.597Z] Error: Failed to start the connection: null
push../node_modules/@aspnet/signalr/dist/esm/Utils.js.ConsoleLogger.log @ Utils.js:203
(anonymous) @ HttpConnection.js:228
step @ HttpConnection.js:33
(anonymous) @ HttpConnection.js:14
rejected @ HttpConnection.js:6
invoke @ zone-evergreen.js:359
onInvoke @ core.js:39699
invoke @ zone-evergreen.js:358
run @ zone-evergreen.js:124
(anonymous) @ zone-evergreen.js:855
invokeTask @ zone-evergreen.js:391
onInvokeTask @ core.js:39680
invokeTask @ zone-evergreen.js:390
runTask @ zone-evergreen.js:168
drainMicroTaskQueue @ zone-evergreen.js:559
invokeTask @ zone-evergreen.js:469
invokeTask @ zone-evergreen.js:1603
globalZoneAwareCallback @ zone-evergreen.js:1629
error (async)
customScheduleGlobal @ zone-evergreen.js:1742
scheduleTask @ zone-evergreen.js:378
onScheduleTask @ zone-evergreen.js:272
scheduleTask @ zone-evergreen.js:372
scheduleTask @ zone-evergreen.js:211
scheduleEventTask @ zone-evergreen.js:237
(anonymous) @ zone-evergreen.js:1911
desc.set @ zone-evergreen.js:1252
(anonymous) @ WebSocketTransport.js:96
ZoneAwarePromise @ zone-evergreen.js:876
(anonymous) @ WebSocketTransport.js:71
step @ WebSocketTransport.js:33
(anonymous) @ WebSocketTransport.js:14
(anonymous) @ WebSocketTransport.js:8
ZoneAwarePromise @ zone-evergreen.js:876
push../node_modules/@aspnet/signalr/dist/esm/WebSocketTransport.js.__awaiter @ WebSocketTransport.js:4
push../node_modules/@aspnet/signalr/dist/esm/WebSocketTransport.js.WebSocketTransport.connect @ WebSocketTransport.js:53
(anonymous) @ HttpConnection.js:157
step @ HttpConnection.js:33
(anonymous) @ HttpConnection.js:14
(anonymous) @ HttpConnection.js:8
ZoneAwarePromise @ zone-evergreen.js:876
push../node_modules/@aspnet/signalr/dist/esm/HttpConnection.js.__awaiter @ HttpConnection.js:4
push../node_modules/@aspnet/signalr/dist/esm/HttpConnection.js.HttpConnection.startInternal @ HttpConnection.js:140
push../node_modules/@aspnet/signalr/dist/esm/HttpConnection.js.HttpConnection.start @ HttpConnection.js:96
(anonymous) @ HubConnection.js:112
step @ HubConnection.js:33
(anonymous) @ HubConnection.js:14
(anonymous) @ HubConnection.js:8
ZoneAwarePromise @ zone-evergreen.js:876
push../node_modules/@aspnet/signalr/dist/esm/HubConnection.js.__awaiter @ HubConnection.js:4
push../node_modules/@aspnet/signalr/dist/esm/HubConnection.js.HubConnection.start @ HubConnection.js:96
ngOnInit @ app.component.ts:25
checkAndUpdateDirectiveInline @ core.js:31910
checkAndUpdateNodeInline @ core.js:44367
checkAndUpdateNode @ core.js:44306
debugCheckAndUpdateNode @ core.js:45328
debugCheckDirectivesFn @ core.js:45271
eval @ AppComponent_Host.ngfactory.js? [sm]:1
debugUpdateDirectives @ core.js:45259
checkAndUpdateView @ core.js:44271
callWithDebugContext @ core.js:45632
debugCheckAndUpdateView @ core.js:45194
detectChanges @ core.js:31126
tick @ core.js:41045
_loadComponent @ core.js:41096
bootstrap @ core.js:41019
(anonymous) @ core.js:40619
_moduleDoBootstrap @ core.js:40615
(anonymous) @ core.js:40570
invoke @ zone-evergreen.js:359
onInvoke @ core.js:39699
invoke @ zone-evergreen.js:358
run @ zone-evergreen.js:124
(anonymous) @ zone-evergreen.js:855
invokeTask @ zone-evergreen.js:391
onInvokeTask @ core.js:39680
invokeTask @ zone-evergreen.js:390
runTask @ zone-evergreen.js:168
drainMicroTaskQueue @ zone-evergreen.js:559
Promise.then (async)
scheduleMicroTask @ zone-evergreen.js:542
scheduleTask @ zone-evergreen.js:381
scheduleTask @ zone-evergreen.js:211
scheduleMicroTask @ zone-evergreen.js:231
scheduleResolveOrReject @ zone-evergreen.js:845
then @ zone-evergreen.js:955
bootstrapModule @ core.js:40600
./src/main.ts @ main.ts:11
__webpack_require__ @ bootstrap:79
0 @ main.ts:12
__webpack_require__ @ bootstrap:79
checkDeferredModules @ bootstrap:45
webpackJsonpCallback @ bootstrap:32
(anonymous) @ main.js:1
Show 48 more frames
app.component.ts:27 null
...