SignalR Java client unable to open WebSocket
See original GitHub issueDescribe the bug
I’m unable to connect to a ASP.NET Core SignalR hub from the Java client. I’ll specify all versions of things below to hopefully make this more understandable.
Every time I start the HubConnection object, I get the following error:
Aug 08, 2019 4:21:12 PM com.microsoft.signalr.OkHttpWebSocketWrapper$SignalRWebSocketListener onFailure
SEVERE: WebSocket closed from an error: Expected HTTP 101 response but was '200 OK'.
Aug 08, 2019 4:21:12 PM com.microsoft.signalr.WebSocketTransport onClose
INFO: WebSocket connection stopping with code null and reason 'Expected HTTP 101 response but was '200 OK''.
Aug 08, 2019 4:21:12 PM com.microsoft.signalr.HubConnection stopConnection
SEVERE: HubConnection disconnected with an error Expected HTTP 101 response but was '200 OK'.
Aug 08, 2019 4:21:12 PM com.microsoft.signalr.HubConnection stopConnection
INFO: HubConnection stopped.
I’ve confirmed that WebSockets are enabled on the hub (as I can see it as an option returned during the negotiation phase), eg:
{
"connectionId": "...",
"availableTransports": [
{
"transport": "WebSockets",
"transferFormats": [
"Text",
"Binary"
]
},
{
"transport": "ServerSentEvents",
"transferFormats": [
"Text"
]
},
{
"transport": "LongPolling",
"transferFormats": [
"Text",
"Binary"
]
}
]
}
I’ve also tried setting shouldSkipNegotiate() on the Java client, and making sure that only the WebSocket transport was configured for the hub, but that yielded the same result.
To Reproduce
Versions
- Microsoft.AspNetCore.App 2.2.0
- Microsoft.AspNetCore.SignalR 1.1.0
- Java 1.8.0_77
- com.microsoft.signalr 3.0.0-preview7.19365.7
- Build a HubConnection object, with an access token provider. Eg:
hubConnection = HubConnectionBuilder.create("http://localhost:52929/rtc")
.withAccessTokenProvider(Single.defer(() -> {
String token = getToken("username", "password"); // token fetch logic
return Single.just(token);
}))
.build();
- Start the HubConnection
- Receive the error above
Expected behavior
I expect the client to connect to the hub, and receive messages.
Additional context
I originally picked this issue up while writing a module for a 3rd party product, with an embedded SignalR client. I’ve replicated this in a standalone Java program though, so I’m rolling with the standalone program until I can confirm it works without any interference from the 3rd party product.
Include the output of dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.2.401
Commit: 729b316c13
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.401\
Host (useful for support):
Version: 2.2.6
Commit: 7dac9b1b51
.NET Core SDKs installed:
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.401 [C:\Program Files\dotnet\sdk]
2.1.403 [C:\Program Files\dotnet\sdk]
2.1.502 [C:\Program Files\dotnet\sdk]
2.1.700 [C:\Program Files\dotnet\sdk]
2.2.101 [C:\Program Files\dotnet\sdk]
2.2.103 [C:\Program Files\dotnet\sdk]
2.2.300 [C:\Program Files\dotnet\sdk]
2.2.401 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.3-servicing-26724-03 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (5 by maintainers)
Sure. So try running in Kestrel perhaps?
Ok I’ve got it now. In my web.config file, I had a rule that handled HTML5 routes for the SPA website that it hosts. It had some exclusions in for the /api/* and /health endpoints, but not for the SignalR endpoints. Entirely my fault for this one.😞
After I added
|^/rtc|^/metadata
to the “Add rule to negate directories” section, it started working in IIS Express.At least that explains why it was working in Kestrel, and not IIS Express (or I imagine IIS if I was to test using that).