最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

flutter - SignalR WebSocket handshake fails with error code 200 when testing locally on Azure App Service - Stack Overflow

programmeradmin1浏览0评论

// 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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论