How to get a .Net Framework SignalR client to connect to .Net Core SignalR Server?

Net Wang 20 Reputation points
2025-01-09T15:43:06.4633333+00:00

SignalR Server:

IIS ASP.Net Core 8.0,

Microsoft.AspNetCore.SignalR 1.1.0,

Microsoft.AspNetCore.SignalR.Core 1.1.0,

Angular,

Javascript (Browser) successfully made SignalR connection

SignalR Client 1:

IIS ASP.NET 4.8,

Microsoft.AspNetCore.SignalR.Client 8.0.0.0,

Microsoft.AspNetCore.SignalR.Client.Core 8.0.0.0,

successfully made SignalR connection

SignalR Client 2:

Windows C# Desktop UI App .NET Framework 4.8,

Microsoft.AspNetCore.SignalR.Client 8.0.0.0,

Microsoft.AspNetCore.SignalR.Client.Core 8.0.0.0,

Failed to make SignalR connection.

Connection = new HubConnectionBuilder()

.WithUrl("http://localhost/QMOSRFactor/rfactor",

    options => {

        options.Transports = HttpTransportType.WebSockets;

    })

.WithAutomaticReconnect()

.Build();

await Connection.StartAsync();

For SignalR Client 2, after calling await Connection.StartAsync(), nothing happened. No error in Visual Studio Output. No exceptions throwed.

If I wrapped the above code in netstandard2.0 library. Reference this library in Client 2 project. Nothing happened. No error in Visual Studio Output. No exceptions.

Azure SignalR Service
Azure SignalR Service
An Azure service that is used for adding real-time communications to web applications.
153 questions
{count} votes

Accepted answer
  1. Bhargavi Naragani 410 Reputation points Microsoft Vendor
    2025-01-27T04:46:05.4166667+00:00

    Hi @Net Wang,
    I'm glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer.

    Solution:
    Solved the issue by embedding in Task.Factory.StartNew. It seems that it should use a new thread different from Windows Form UI thread.

    Task.Factory.StartNew(() => {
               Connection = new HubConnectionBuilder()
                  .WithUrl("http://localhost/QMOSRFactor/rfactor", options => {
                      options.Transports = HttpTransportType.WebSockets;
                  })
                 .ConfigureLogging(logging => {
                      logging.SetMinimumLevel(LogLevel.Trace);
                      logging.AddConsole();
                 })
                 .WithAutomaticReconnect()
                 .Build();
           });
    

    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Net Wang 20 Reputation points
    2025-01-26T15:51:28.4733333+00:00

    Solved the issue by embedding in Task.Factory.StartNew. It seems that it should use a new thread different from Windows Form UI thread.

           Task.Factory.StartNew(() => {
               Connection = new HubConnectionBuilder()
                  .WithUrl("http://localhost/QMOSRFactor/rfactor", options => {
                      options.Transports = HttpTransportType.WebSockets;
                  })
                 .ConfigureLogging(logging => {
                      logging.SetMinimumLevel(LogLevel.Trace);
                      logging.AddConsole();
                 })
                 .WithAutomaticReconnect()
                 .Build();
           });
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.