我正在使用以下堆栈的SignalR Core Web应用程序:
客户端正在使用SignalR NPM包(@ aspnet / signalr)。
应用程序配置如下:
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy(
"CorsPolicy",
builder => builder
.AllowCredentials()
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
});
services.AddSignalR();
}
public void Configure(IApplicationBuilder app)
{
app.UseCors("CorsPolicy");
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseWebSockets();
app.UseSignalR(routes =>
{
routes.MapHub<ClientHub>("/hubs/notifications");
});
}
在http://localhost
本地运行时,客户端使用WS协议进行连接。但是,当部署在Azure App Service中时,它会回退到SSE。
浏览器日志显示:
WebSocket connection to 'wss://xxxxxx.azurewebsites.net/hubs/notifications?id=ZRniWKpMLMPIyLhS5RSyAg' failed: Error during WebSocket handshake: Unexpected response code: 503
Information: SSE connected to https://xxxxxx.azurewebsites.net/hubs/notifications?id=ig47oOdQzbasdgrlr0cHaw
negotiate
方法似乎返回对Websockets的支持:
{"connectionId":"ZRniWKpMLMPIyLhS5RSyAg",
"availableTransports":[
{"transport":"WebSockets","transferFormats":["Text","Binary"]},
{"transport":"ServerSentEvents","transferFormats":["Text"]},
{"transport":"LongPolling","transferFormats":["Text","Binary"]}]
}
我错过了什么吗?或者WSS尚未受支持?