SignalR client is reconnected after Owin restart, but message is not published

前端 未结 3 2127
野的像风
野的像风 2021-01-02 18:55

Setup:

  1. SignalRServer console app: Microsoft.AspNet.SignalR.SelfHost v2.0.3
  2. SignalRClient console app: Microsoft.A
3条回答
  •  旧时难觅i
    2021-01-02 19:18

    Stian's answer is great. But if you need to use static methods defined in GlobalHost, you need to assign the Dependency resolver to GlobalHost.

    The following works for me:

    public void Configuration(IAppBuilder app)
    {
        .... Other configurations ....
        GlobalHost.DependencyResolver = new DefaultDependencyResolver();
        app.MapSignalR();
    }
    

    I defined the hub context this way:

    public sealed class RemoteAdminHub : Hub
    {
        #region Properties
    
        /// 
        /// Gets the SignalR Hub context.
        /// 
        public static IHubContext HubContext
        {
            get
            {
                return GlobalHost.ConnectionManager.GetHubContext();
            }
        }
    
        #endregion
    }
    

提交回复
热议问题