SignalR WebSockets Angular client - Handshake was canceled, .net core client all ok
See original GitHub issueDescribe the bug
SignalR .Net Core 1 instance hosted on docker. Microsoft.AspNetCore.SignalR 1.1.0 Microsoft.AspNetCore.SignalR.Protocols.MessagePack 1.1.0 Microsoft.AspNetCore.SignalR.StackExchangeRedis 1.1.0
Im use WebSockets, MessagePack. Nginx 1.15 as reverse proxy.
.Net ore client (wpf signalr test app) work fine. Microsoft.AspNetCore.SignalR.Client 1.1.0 Microsoft.AspNetCore.SignalR.Protocols.MessagePack 1.1.0
JS client on angular 7 app throw connection errror. “@aspnet/signalr”: “^1.1.2”, “@aspnet/signalr-protocol-msgpack”: “^1.1.0”,
You can use test server hub https://whitchhunt.ru/api/hubs/hunt - it’s just for fun. Every 1 min he send to all client’s “Notify” message with server time.
Server code:
public class HuntHub : Hub
{
public Task SendToAll(string message)
{
return Clients.All.SendAsync("Notify", message);
}
public override async Task OnConnectedAsync()
{
await Clients.All.SendAsync("Notify", $"{Context.ConnectionId} вошел в чат");
await base.OnConnectedAsync();
}
public override async Task OnDisconnectedAsync(Exception exception)
{
await Clients.All.SendAsync("Notify", $"{Context.ConnectionId} покинул в чат");
await base.OnDisconnectedAsync(exception);
}
}
services.AddSignalR(x =>
{
x.EnableDetailedErrors = true;
x.HandshakeTimeout = TimeSpan.FromMinutes(1);
})
.AddMessagePackProtocol()
.AddStackExchangeRedis(o =>
app.UseWebSockets();
app.UseSignalR(routes =>
{
var desiredTransports = HttpTransportType.WebSockets;
routes.MapHub<HuntHub>("/api/hubs/hunt", options => options.Transports = desiredTransports);
});
Nginx conf:
location ~* ^/api/hubs/ {
resolver 127.0.0.11 valid=10s;
set $upstream tasks.whitchhunt-api:80;
proxy_pass http://$upstream;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
Wpf connection:
connection = new HubConnectionBuilder()
.WithUrl("https://whitchhunt.ru/api/hubs/hunt", options => { options.Transports = HttpTransportType.WebSockets; })
.AddMessagePackProtocol()
.Build();
connection.On<string>("Notify", (message) =>
{
this.Dispatcher.Invoke(() =>
{
var newMessage = $"Notify {message}";
messagesList.Items.Add(newMessage);
});
});
Server side log with .net core client:
OnConnectedAsync started.
dbug: Microsoft.AspNetCore.SignalR.Internal.DefaultHubProtocolResolver[2]
Found protocol implementation for requested protocol: messagepack.
info: Microsoft.AspNetCore.SignalR.HubConnectionContext[1]
Completed connection handshake. Using HubProtocol 'messagepack'.
Angular connection:
this.hubConnection = new HubConnectionBuilder()
.configureLogging(LogLevel.Debug)
.withUrl(this.baseUrl + '/api/hubs/hunt', {
transport: HttpTransportType.WebSockets,
})
.withHubProtocol(new MessagePackHubProtocol())
.build();
this.hubConnection.on('Notify', (data: any) => {
console.log(data);
});
Angular app log:
[2019-03-15T08:17:51.658Z] Debug: Starting HubConnection.
[2019-03-15T08:17:51.662Z] Debug: Starting connection with transfer format 'Binary'.
[2019-03-15T08:17:51.666Z] Debug: Sending negotiation request: https://whitchhunt.ru/api/hubs/hunt/negotiate.
[2019-03-15T08:17:51.733Z] Debug: Selecting transport 'WebSockets'.
XHR finished loading: POST "https://whitchhunt.ru/api/hubs/hunt/negotiate".
[2019-03-15T08:17:51.955Z] Information: WebSocket connected to wss://whitchhunt.ru/api/hubs/hunt?id=zFq_vKHYJsT9OZ0G5j4IFQ.
[2019-03-15T08:17:51.956Z] Debug: Sending handshake request.
WebSocket is not in the OPEN state
[2019-03-15T08:18:51.950Z] Error: Server returned handshake error: Handshake was canceled.
[2019-03-15T08:18:51.953Z] Error: Connection disconnected with error 'Error: Server returned handshake error: Handshake was canceled.'.
ERROR Error: Uncaught (in promise): Server returned handshake error: Handshake was canceled.
Server side log with js client:
dbug: Microsoft.AspNetCore.SignalR.HubConnectionHandler[5]
OnConnectedAsync started.
dbug: Microsoft.AspNetCore.SignalR.HubConnectionContext[2]
Handshake was canceled.
dbug: Microsoft.AspNetCore.Http.Connections.Internal.Transports.WebSocketsTransport[7]
Waiting for the client to close the socket.
dbug: Microsoft.AspNetCore.Http.Connections.Internal.Transports.WebSocketsTransport[2]
Socket closed.
dbug: Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionManager[2]
Removing connection zFq_vKHYJsT9OZ0G5j4IFQ from the list of connections.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Related StackOverflow Question
angular.saz.txt angular.txt angular_code.txt whitchhunt.ru.har.txt wpf.saz.txt wpf.txt wpf_code.txt
No, the SignalR server components are part of ASP.NET Core and you cannot cross versions like this.
If you are using the SignalR .NET Client you can mix versions like this.