Nopcommerce 4.1 插件中的 SignalR

SignalR at Nopcommerce 4.1 Plugin

我正在尝试在 Nopcommerce 4.1 插件中实现 SignalR。但是出现以下错误。

与 'wss://localhost:44356/message?id=P70y4-FWNVPuLVFhKTaaKQ' 的 WebSocket 连接失败:WebSocket 握手期间出错:意外的响应代码:404

无法启动传输'WebSockets':未定义

无法启动连接:错误:无法初始化任何可用的传输。

未捕获(承诺)错误:无法初始化任何可用传输。

下面是集线器启动。以下方法在每次启动时调用。

public class AnnouncementHubAtStartUp : INopStartup
{
        public int Order => int.MaxValue;

        public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
        {
            services.AddSignalR();
        }

        public void Configure(IApplicationBuilder application)
        {
            application.UseFileServer();

            application.UseSignalR(routes =>
            {
                routes.MapHub<MessageHub>("/message");
            });
        }
}

下面是我的中心Class

public class MessageHub : Hub
{
        public Task Send(string message)
        {
            return Clients.All.SendAsync("Send", message);
        }
}

我的控制器是

public class LiveAnnouncementController : BaseAdminController
{
    private IHubContext<MessageHub> _messageHubContext;

    public LiveAnnouncementController(IHubContext<MessageHub> messageHubContext)
    {
      _messageHubContext = messageHubContext;
    }

     [HttpPost]
        public IActionResult Announcement(AnnouncementModel model)
        {
            AnnouncementDomain objOfAnnouncementDomain = new AnnouncementDomain();
            objOfAnnouncementDomain.Name=model.Name;
            objOfAnnouncementDomain.Body=model.Body;
            objOfAnnouncementDomain.IsActive=model.IsActive;
            objOfAnnouncementDomain.ShowingToDate=model.ShowingToDate;
            objOfAnnouncementDomain.CreateDate = DateTime.UtcNow;
            _announcementService.Insert(objOfAnnouncementDomain);

            if (model.IsActive == true)
            {
                _messageHubContext.Clients.All.SendAsync("send", model.Body.ToString() +
DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"));

            }

            return RedirectToAction("AnnouncementList");
        }
}

我需要降低 AnnouncementHubAtStartUp 的顺序 属性。因为下面的扩展方法

   application.UseSignalR(routes =>
            {
                routes.MapHub<MessageHub>("/message");
            });

应该在 NopMvcStartup.

之前执行

因此订单必须小于 1000。如果我将订单更改为 999,则集线器会正常连接,否则不会。

更改后的代码是

public class AnnouncementHubAtStartUp : INopStartup
{
    public int Order => 999;

    public void ConfigureServices(IServiceCollection services, IConfiguration configuration)
    {
        services.AddSignalR();
    }

    public void Configure(IApplicationBuilder application)
    {
        application.UseSignalR(routes =>
        {
            routes.MapHub<MessageHub>("/message");
        });
    }


}