Search code examples
javascript.net-coreaspnetboilerplateasp.net-core-signalr

SignalR not falling back to older protocols


I have an Angular 6/.NETCore ASP.NET Boilerplate application which uses SignalR to allow the server to execute some client code. The version of the Abp.AspNetCore.SignalR library is 3.5.0-preview3, which uses Microsoft.AspNetCore.SignalR version 1.0.0-preview1. The SignalR management code is the one shipped in the official template of ASP.NET Boilerplate.

Everything works fine during the development in Visual Studio with IIS Express.

Now I have published the application on a Windows Server 2008 R2, which ships an IIS 7 server. The application starts up but in the Chrome console I see this error:

signalr.min.js:13 WebSocket connection to 'ws://MY-HOSTNAME:21021//signalr failed: Error during WebSocket handshake: Unexpected response code: 400
signalr.min.js:13 Error: Failed to start the connection. undefined

The same problem occurs on Edge:

Starting connection using WebSockets transport abp.js (350,1) Error:
Failed to start the connection. undefined signalr.min.js (13,25649)
SCRIPT12008: SCRIPT12008: WebSocket Error: Incorrect HTTP response.
Status code 400, Bad Request

Here I can see that SignalR is supported in Windows Server 2008 R2, even though it is not supported in IIS 7 (8 is required). It's also written that SignalR is supposed to fallback to some other protocol in case the server does not support WebSocket (my situation).

It is strange that the browser is trying to use the WebSocket protocol, even though it is not supported by the server.

Do you have any clue for this problem? May I be missing something?

UPDATE

I upgraded all the ASP.NET boilerplate libraries to 3.8.1, including the SignalR library. The error does not show up, so it is a old bug of previous versions.

Now I have this console log:

Starting connection using WebSockets transport
Failed to start the connection: Error: Unable to initialize any of the available transports.
Cannot start the connection using WebSockets transport. Unable to initialize any of the available transports.
Starting connection using ServerSentEvents transport
Information: SSE connected to http://MY-HOST:21021//signalr?asdasdasd
Connected to SignalR server!
Registered to the SignalR server!

So at first it tells that it fails connecting though SignalR with any protocol, but then it succeeds with the ServerSentEvents protocol. Is it connecting or not?


Solution

  • The version of the Abp.AspNetCore.SignalR library is 3.5.0-preview3, which uses Microsoft.AspNetCore.SignalR version 1.0.0-preview1.

    Upgrade to Abp.AspNetCore.SignalR 3.7.0+ (current: 3.8.2) for a stable release version.

    So at first it tells that it fails connecting though SignalR with any protocol, but then it succeeds with the ServerSentEvents protocol. Is it connecting or not?

    As it says, it is connected using the ServerSentEvents transport. You can see why here:

    abp.log.debug('Cannot start the connection using ' + signalR.HttpTransportType[transport] + ' transport. ' + error.message);
    if (transport !== signalR.HttpTransportType.LongPolling) {
        return start(transport + 1);
    }
    

    The error.message ("Unable to initialize any of the available transports.") is a little misleading because only one transport is specified at a time.