Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server

I am using a console application for a server and my client is an angular 2 app. I get an error of

Error: Failed to start the connection: Error: Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server.

I got my hub setup and my Startup.cs looks like this:

public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // Branch the pipeline here for requests that start with "/signalr"
            app.Map("/signalr", map =>
            {
                // Setup the CORS middleware to run before SignalR.
                // By default this will allow all origins. You can 
                // configure the set of origins and/or http verbs by
                // providing a cors options with a different policy.
                map.UseCors(CorsOptions.AllowAll);
                var hubConfiguration = new HubConfiguration
                {
                    // You can enable JSONP by uncommenting line below.
                    // JSONP requests are insecure but some older browsers (and some
                    // versions of IE) require JSONP to work cross domain
                    // EnableJSONP = true
                };
                // Run the SignalR pipeline. We're not using MapSignalR
                // since this branch already runs under the "/signalr"
                // path.

                hubConfiguration.EnableDetailedErrors = true;
                map.RunSignalR(hubConfiguration);
            });
        }
    }

and in my angular app, this is what I have in the app.component.ts

ngOnInit(): void {
    this.nick = window.prompt('Your name:', 'John');

    this.hubConnection = new HubConnectionBuilder().withUrl("http://localhost:8089/signalr").build();

    this.hubConnection
      .start()
      .then(() => console.log('Connection started!'))
      .catch(err => console.log('Error while establishing connection :('));

    this.hubConnection.on('addMessage', (nick: string, receivedMessage: string) => {
      const text = `${nick}: ${receivedMessage}`;
      this.messages.push(text); 
    });
  }

  public sendMessage(): void {
    this.hubConnection
      .invoke('sendToAll', this.nick, this.message)
      .catch(err => console.error(err));
  }

I know my error says to connect to asp.net core signalr server but how do i do this?

like image 528
Ibanez1408 Avatar asked Dec 20 '18 03:12

Ibanez1408


3 Answers

As Stefano and Ibanez commented is a problem with "versions".

The client of SignalR you are using is able to connect to ASPNET Core but not ASPNET server like error mentioned.

If you know ASPNET Core is a split from .Net Framework (CLR) based for multiplatform.

Then you have two options over this scenario.

First you can change your client side if you desire to continue using ASPNET server side. Then change the library you using to one that supports ASPNET. Give a look: SIGNALR - ASPNET vs ASPNET Core

Second you can change your server side and use ASPNET Core for SignalR, as a microservice, for example. Then continue implementing your client with ASPNET Core SignalR library.

like image 71
Sam Avatar answered Oct 20 '22 23:10

Sam


Have you solved your issue? As mentioned by JohnB, this is likely an issue of a core client trying to access a .NET framework hub.

If you're trying to connect to a .NET framework hub, you're gonna want to use the signalr package.

Otherwise, if you're hub is a .NET core application, you'll instead want to use @aspnet/signalr.

like image 42
Stefano Branco Avatar answered Oct 20 '22 21:10

Stefano Branco


Not sure about but your problem is related to the client library you are using

The error occurs because new SignalR does not allow you to use old server & new client or new server & old client look this and this

Your possible status:

According to your example, like this he tried to connect to the old singleR server with Angular 5. We can understand from how it tries to get the HubConnection instance: look here

In your case, you used HubConnectionBuilder, so you wrote the new core singleR. The reason for the error may be that the referenced library is outdated.

import {Component, OnInit} from '@ angular / core';
import {HubConnection} from '@ aspnet / signalr-client';

Possible Solution:

Update

@aspnet/signalr-client

to

@aspnet/signalr

like image 39
Hamit YILDIRIM Avatar answered Oct 20 '22 23:10

Hamit YILDIRIM