Skip to content
Advertisement

Connecting NodeJS app to SignalR (with .NET Core 3)

I have a server running SignalR using .NET Core 3. The project was started with the template and I followed a guide (https://learn.microsoft.com/en-gb/aspnet/core/tutorials/signalr?tabs=visual-studio&view=aspnetcore-3.0).

I have created a clone of the project, and can successfully connect to the server and can receive messages as expected. This also means I added CORS.

I want to be able to use SignalR in a Node JS environment, but the connection stucks at “Negotiation” I have created a brand new folder, ran npm init -y and npm i @microsoft/signalr. Created a new js file called main.js, which looks like this:

JavaScript

after running it with node main.js I get the following error in console

JavaScript

It seems like it’s timing out. The server, client and nodejs app are all hosted locally. I made sure to check that the signalr version installed with npm i match the version of server (3.0.1). I even extracted the js files in node_modules and used them for another client (made with the VS template) and it can connect just fine.

I have no clue how to debug any further. I tried to attach to the server using VS, but I couldnt get any information. The server is hosted using IIS Express (started via Visual Studio). Any tips on how to debug any further? otherwise I might downgrade to a previous .NET Core version with another signalr version

My startup.cs code in VS

JavaScript

Advertisement

Answer

Don’t know if this is the root cause or not, but I stumbled on this in my setup.

The default settings for IISExpress in Visual Studio do not listen on the same port for http and https. I was using the SSL port in my node.js file, but using the http protocol. I suspect your problem might be the same, since VS usually defaults to the 44000 range for SSL ports.

What confused me was the fact that my browser would pop up on the SSL port during debugging.

In my case, I checked ./Properties/launchSettings.json to get the ports being used:

JavaScript

Then updated my js file accordingly:

JavaScript

And voila. Run the app in Visual Studio 2019, and then on the command line:

JavaScript
Advertisement