微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法使用任何可用传输连接 SignalR 和 Ocelot 网关错误 404“没有与该 ID 的连接”

如何解决无法使用任何可用传输连接 SignalR 和 Ocelot 网关错误 404“没有与该 ID 的连接”

我有一个 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 举报,一经查实,本站将立刻删除。