Hi I am trying to use signalR with asp.net mvc 5 and angular 7 , but unable to establish the connection between the hub
Here are my codes
Angular 7
import { Component, OnInit } from '@angular/core';
import { HubConnection, HubConnectionBuilder } from '@aspnet/signalr';
import * as $ from '@aspnet/signalr'
@Component({
selector: 'app-admin-dashboard',
templateUrl: './admin-dashboard.component.html',
styleUrls: ['./admin-dashboard.component.scss']
})
export class AdminDashboardComponent implements OnInit {
private _hubConnection: HubConnection;
constructor() {
this._hubConnection = new HubConnectionBuilder()
  .withUrl("http://localhost:4200/hub/cashnet", {
    skipNegotiation: true,
    transport: $.HttpTransportType.WebSockets
  })
  .configureLogging($.LogLevel.Information)
  .build();
this._hubConnection.start().then(() => {
  console.log('Hub connection started');
}).catch(err => {
  console.log('Error while establishing connection :(')
});
this._hubConnection.on('sendMessage', (MachineId: string) => {
  alert(MachineId);
});
}
  ngOnInit(): void { 
}
}
Startup.cs
 public partial class Startup
 {
    public void Configuration(IAppBuilder app)
    {
        ConfigureAuth(app);
        app.MapSignalR(); 
    }
 }
Hub/CashnetHub.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
namespace CashNet_API.Hubs
{
public class CashnetHub : Hub
{
    public void sendMachineUpdate(string MachineId)
    {
        Clients.All.sendMessage(MachineId);
    }
 }
}
there is support for ASP.NET Core but we are not using core for this application
this is what i am getting in console Error in Console :img
thanks in advance
You cannot use an ASP.NET Core SignalR client to connect to an ASP.NET SignalR server. They are incompatible. The @aspnet/signalr npm package is only for ASP.NET Core SignalR. You want to use https://www.npmjs.com/package/signalr for an ASP.NET SignalR server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With