问题描述
我有一个 React 网站,我正在尝试通过 ocelot 网关连接到我的 .net 核心服务器上的 SignalR 集线器。
我无法连接到集线器并收到 404 错误“与该 ID 无连接”。我只有一个服务器实例在运行,并且不涉及负载平衡器。 SignalR Hub Request SignalR Hub Response
即使谈判总是成功的。
{"negotiateVersion":1,"connectionId":"BWKJZHDMQkfYV9Qz5RNtHg","connectionToken":"nZjyl8Gpm7jF1MtWipHdPw","availableTransports":[{"transport":"WebSockets","transferFormats":["Text","Binary"]},{"transport":"ServerSentEvents","transferFormats":["Text"]},{"transport":"LongPolling","Binary"]}]}
WebSocket 和服务器发送的事件根本不起作用,在长轮询中,返回 404“与该 ID 无连接”。
网络通话记录为:Network calls logs
我已经为豹猫添加了所有可能的路线。我现在不知道该做什么。
{
"DownstreamPathTemplate": "/bookingCancelNotificationHub/{everything}","ReRouteIsCaseSensitive": false,"DownstreamScheme": "ws","DownstreamHostAndPorts": [
{
"Host": "localhost","Port": 5009
}
],"UpstreamPathTemplate": "/bookingCancelNotificationHub/{everything}","UpstreamHttpMethod": [ "GET","POST","PUT","DELETE","OPTIONS" ]
},{
"DownstreamPathTemplate": "/bookingCancelNotificationHub?{everything}","UpstreamPathTemplate": "/bookingCancelNotificationHub?{everything}",{
"DownstreamPathTemplate": "/bookingCancelNotificationHub","UpstreamPathTemplate": "/bookingCancelNotificationHub",
我观察到响应协商调用返回的 connectionId 未用于连接到集线器,而是将 connectionToken 值用作“id”查询字符串参数的值。
https://xxxx.se/bookingCancelNotificationHub?id=OHhTeLj9uKVHGh-nBeIBwA&access_token=7b082653-7283-41ef-8337-a22b6dc239f1%7CPASS
我的 Ocelot Gateway 项目中有以下配置
ConfigureServices(services =>
{
services.AddCors(options =>
{
var isCustomOriginsAllowed = _configuration.GetValue<bool>("IsCustomOriginsAllowed");
if (isCustomOriginsAllowed)
options.AddPolicy("CorsPolicy",builder => builder.WithOrigins(AllowedOrigins)
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
);
else
options.AddPolicy("CorsPolicy",builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
);
});
services.AddSignalR(options => options.EnableDetailedErrors = true);
services.AddOcelot().AddDelegatingHandler<NoGzipDelegatingHandler>(true);
})
.Configure(app =>
{
app.UseCors("CorsPolicy");
app.UseWebSockets();
app.USEOcelot().Wait();
});
我的集线器配置是:
app.UseHttpsRedirection();
app.UseCors("CorsPolicy");
app.UseRouting();
app.UseAuthentication();
app.UseEndpoints(endpoints => {
endpoints.MapControllers();
endpoints.MapHub<BookingCancelNotificationHub>("/bookingCancelNotificationHub");
});
规格
- 豹猫版本:15.0.6
- @microsoft/signalr 版本:5.0.1(也降级到 3.1.0 版)
- .Net 核心:3.1
- 平台:Windows
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)