Encountering 'WebSocketException (0x80004005): The server returned status code '404' when status code '101' was expected' when signalr client starts a hub connection.

Qian Zhang 6 Reputation points
2022-11-21T22:00:12.137+00:00

We have a .net core signalr client trying to establish a connection to signalr hub web application and a signalr service. The client successfully connects to the hub and signalr service, but fails when attempting to start the websocket transport to the signalr service. This results in the server returning status code '404'.

Signalr client log:

13:55:05.724 Debug: Microsoft.AspNetCore.SignalR.Client.HubConnection: Starting: Starting HubConnection.  
13:55:05.905 Debug: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection: Starting: Starting HttpConnection.  
13:55:05.982 Debug: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection: EstablishingConnection: Establishing connection with server at 'https://<hub web app url>'.  
13:55:07.541 Debug: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection: Established: Established connection '(null)' with the server.  
13:55:07.549 Debug: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection: EstablishingConnection: Establishing connection with server at 'https://<signalr service url>'.  
13:55:12.920 Debug: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection: Established: Established connection 'r5p09qYjaIYEDmVaD2rK1Q5dbce30c1' with the server.  
13:55:12.945 Debug: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection: StartingTransport: Starting transport 'WebSockets' with Url: https://<signalr service url>.  
13:55:12.993 Information: Microsoft.AspNetCore.Http.Connections.Client.Internal.WebSocketsTransport: StartTransport: Starting transport. Transfer mode: Binary. Url: 'wss://<signalr service url>'.  
13:55:18.410 Error: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection: ErrorStartingTransport: Failed to start connection. Error starting transport 'WebSockets'.  
13:55:18.412 Debug: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection: TransportFailed: Skipping transport WebSockets because it failed to initialize.  
13:55:18.415 Debug: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection: TransportDisabledByClient: Skipping transport ServerSentEvents because it was disabled by the client.  
13:55:18.415 Debug: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection: TransportDisabledByClient: Skipping transport LongPolling because it was disabled by the client.  
13:55:18.441 Debug: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection: SkippingDispose: Skipping dispose, connection is already disposed.  
13:55:18.599 Encountered exception starting <App> connection: System.AggregateException: Unable to connect to the server with any of the available transports. (WebSockets failed: The server returned status code '404' when status code '101' was expected.) (ServerSentEvents failed: The transport is disabled by the client.) (LongPolling failed: The transport is disabled by the client.)  
 ---> Microsoft.AspNetCore.Http.Connections.Client.TransportFailedException: WebSockets failed: The server returned status code '404' when status code '101' was expected.  
 ---> System.Net.WebSockets.WebSocketException (0x80004005): The server returned status code '404' when status code '101' was expected.  
   at System.Net.WebSockets.WebSocketHandle.ConnectAsync(Uri uri, CancellationToken cancellationToken, ClientWebSocketOptions options)  
   at System.Net.WebSockets.ClientWebSocket.ConnectAsyncCore(Uri uri, CancellationToken cancellationToken)  
   at Microsoft.AspNetCore.Http.Connections.Client.Internal.WebSocketsTransport.DefaultWebSocketFactory(WebSocketConnectionContext context, CancellationToken cancellationToken)  
   at Microsoft.AspNetCore.Http.Connections.Client.Internal.WebSocketsTransport.StartAsync(Uri url, TransferFormat transferFormat, CancellationToken cancellationToken)  
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.StartTransport(Uri connectUrl, HttpTransportType transportType, TransferFormat transferFormat, CancellationToken cancellationToken)  
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.SelectAndStartTransport(TransferFormat transferFormat, CancellationToken cancellationToken)  
   --- End of inner exception stack trace ---  
   --- End of inner exception stack trace ---  
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.SelectAndStartTransport(TransferFormat transferFormat, CancellationToken cancellationToken)  
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.StartAsyncCore(TransferFormat transferFormat, CancellationToken cancellationToken)  
   at System.Threading.Tasks.ForceAsyncAwaiter.GetResult()  
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.StartAsync(TransferFormat transferFormat, CancellationToken cancellationToken)  
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionFactory.ConnectAsync(EndPoint endPoint, CancellationToken cancellationToken)  
   at Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionFactory.ConnectAsync(EndPoint endPoint, CancellationToken cancellationToken)  
   at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsyncCore(CancellationToken cancellationToken)  
   at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsyncInner(CancellationToken cancellationToken)  
   at System.Threading.Tasks.ForceAsyncAwaiter.GetResult()  
   at Microsoft.AspNetCore.SignalR.Client.HubConnection.StartAsync(CancellationToken cancellationToken)  
 ---> (Inner Exception #1) Microsoft.AspNetCore.Http.Connections.Client.TransportFailedException: ServerSentEvents failed: The transport is disabled by the client.<---  
  
 ---> (Inner Exception #2) Microsoft.AspNetCore.Http.Connections.Client.TransportFailedException: LongPolling failed: The transport is disabled by the client.<---  
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,141 questions
Azure SignalR Service
Azure SignalR Service
An Azure service that is used for adding real-time communications to web applications.
120 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,041 Reputation points
    2022-11-22T17:51:47.497+00:00

    The client’s browser/machine does not support websockets and the fallback to long polling is failing due to configuration.

    0 comments No comments