Dieterg
Dieterg

Reputation: 16368

Connect to signalr core server from signalr 4.6 client

Situation:

The SignalR service is a new feature, thus we want to write this in .net core. The SignalR service is up and running and we can connect from our core projects as follows (simplified console app):

Console.WriteLine("Hello World!");
var connection = new HubConnectionBuilder()
    .WithUrl("http://localhost:5123/myhub")
    .WithConsoleLogger()
    .Build();

connection.StartAsync().Wait();

connection.On<string>("send", data =>
{
    Console.WriteLine($"Received: {data}");
});

Console.ReadLine();

connection.DisposeAsync().Wait();

As long as we're staying in the .net core world, there is no problem. The problem occurs when we're trying to connect from our .net4.6 applications.

Example (also simplified console app):

var connection = new HubConnection("http://localhost:5123/myhub");
var hub = connection.CreateHubProxy("myhub");

connection.Start().ContinueWith(task =>
{
    if (task.IsFaulted)
    {
        Console.WriteLine("There was an error opening the connection: {0}", task.Exception.GetBaseException());
    }
    else
    {
        Console.WriteLine("Connected");
    }
});

hub.On<string>("send", result =>
{
    Console.WriteLine(result);
});


Console.Read();
connection.Stop();

Here we're getting a 404 not found error, using the exact same URL:

There was an error opening the connection: Microsoft.AspNet.SignalR.Client.HttpClientException: StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  X-SourceFiles: =?UTF-8?B?YzpcdXNlcnNcZ29ldGVsZW5kclxzb3VyY2VccmVwb3NcU2lnbmFsUlN0YXJ0ZXJcU2lnbmFsUlN0YXJ0ZXIuQVBJXG15aHViXHNpZ25hbHJcbmVnb3RpYXRl?=
  Date: Wed, 15 Nov 2017 12:16:02 GMT
  Server: Kestrel
  X-Powered-By: ASP.NET
  Content-Length: 0
}
   at Microsoft.AspNet.SignalR.Client.Http.DefaultHttpClient.<>c__DisplayClass5_0.<Get>b__1(HttpResponseMessage responseMessage)
   at Microsoft.AspNet.SignalR.TaskAsyncHelper.<>c__DisplayClass31_0`2.<Then>b__0(Task`1 t)
   at Microsoft.AspNet.SignalR.TaskAsyncHelper.TaskRunners`2.<>c__DisplayClass3_0.<RunTask>b__0(Task`1 t)

The main question is if it is possible to connect from .net 4.6 to .net core signalR hubs?

Upvotes: 2

Views: 2134

Answers (1)

Pawel
Pawel

Reputation: 31620

The previous version of SignalR is not compatible with the Asp.NET Core version of SignalR. This means that you won't be able to use old client with the new server or vice versa. The new client targets netstandard 2.0 meaning you can use it in applications running on full .NET Framework as long as you are running .NET Framework 4.6.1.

Upvotes: 3

Related Questions