// Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSignalR();
builder.Services.AddCors(options =>
{
options.AddPolicy("CorsPolicy", policy =>
{
policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
});
});
var app = builder.Build();
app.UseRouting();
app.UseCors("CorsPolicy");
app.MapHub<ChatHub>("/Chat");
app.Run();
// chat_hub_service.dart
_connection = HubConnectionBuilder()
.withUrl('wss://<your-app>.azurewebsites/Chat',
HttpConnectionOptions(
skipNegotiation: true,
transport: HttpTransportType.webSockets,
))
.build();
await _connection.start();
I'm facing an issue when trying to test my SignalR chat locally while it's hosted on Azure App Service.
Problem Description: When attempting to connect to the SignalR hub, I get the following error:
WebSocket connection to 'wss:Link/Chat' failed: Error during WebSocket handshake: Unexpected response code: 200
also logged error: Exception: The underlying connection was closed before the hub handshake could complete.
Context:
Backend: .NET 8, SignalR Frontend: Flutter using signalr_core Hosting: Azure App Service Backend Configuration: AddSignalR() is included in Program.cs The hub is mapped to /Chat Using IUserIdProvider, QueryStringUserIdProvider CORS is enabled with AllowAnyOrigin Flutter Configuration: skipNegotiation: true, transport: HttpTransportType.webSockets is set in signalr_core
Has anyone encountered a similar issue? Could this be related to WebSockets configuration on Azure App Service? Or is there an issue with signalr_core in Flutter? Any help would be greatly appreciated!
The WebSocket connection should establish successfully. The Flutter client should be able to send and receive messages.
after fixing skip negotiation to false i get error connection to signalr Unexpected end of JSON input