SignalR自助主机服务器无法正常工作

时间:2016-12-19 07:33:45

标签: c# service signalr self-hosting

我们在" c#.net中开发了SignalR自助服务器作为窗口服务"并由移动应用程序作为客户端访问。我们已经借助此链接开发了http://www.asp.net/signalr/overview/deployment/tutorial-signalr-self-host

此窗口服务运行正常,几天后,移动服务器无法响应移动客户端。我们几天都不知道服务器无法正常工作的原因。但是窗口服务运行成功只是没有响应移动客户端。

我们也尝试每6小时重新启动一次服务,但我们仍无法解决问题。我们在服务器端的代码是 启动课程

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseCors(CorsOptions.AllowAll);
        app.MapSignalR(new HubConfiguration() { EnableJSONP = true });
    }
}

服务类

public partial class MobileService : ServiceBase
{
    //SignalR
    private IDisposable signalR { get; set; }
    public string App_ServerURL = null;   
    public MobileHub obj_HubCMobileServer = new MobileHub();     
    public MobileService()
    {
        InitializeComponent();

    }

    protected override void OnStart(string[] args)
    {
        try
        {
                    App_ServerURL = "http://192.168.1.4:8888";
                    obj_HubCMobileServer.Init();
                    Task.Run(() => StartServer());                   
        }
        catch (Exception ex)
        {
            MobileService.Instance.server_Log(ex.Message + ex.StackTrace);
        }
    }

    private void StartServer()
    {
        try
        {
           // server_Log("SignalR server init  " + App_ServerURL);
            signalR = WebApp.Start(App_ServerURL);                
            server_journal("SignalR server started at  " + App_ServerURL);
            GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(50);                               
        }
        catch (Exception ex)
        {                
            server_Log(ex.Message + ex.StackTrace);
            return;
        }

    }

HUB班

public class MobileHub : Hub
{
    IHubContext context = GlobalHost.ConnectionManager.GetHubContext<MobileHub>();

    static readonly object thisLock = new object();
    System.Timers.Timer timer = new System.Timers.Timer();
    public void Init()
    {
        try
        {                
            timer.Enabled = true;
            timer.Start();
            timer.Interval = 1000;
            timer.Elapsed += timer_Elapsed;                 
        }
        catch (Exception ex)
        {
            MobileService.Instance.server_Log(ex.Message + ex.StackTrace);
        }
    }  
    .....
    .....
    .....
    public override Task OnConnected()
    {
                  return base.OnConnected();
    }

    public override Task OnDisconnected(bool stopCalled)
    {           
        return base.OnDisconnected(stopCalled);
    }
    public override Task OnReconnected()
    {

        return (base.OnReconnected());
    }

}

任何人都可以提供解决方案,或者是否每12小时重新启动一次移动SignalR自助服务器?

0 个答案:

没有答案