信号器找不到集线器

时间:2019-01-23 09:33:51

标签: asp.net signalr

我的代码不是我写的,但是我需要运行它,这是一个非常奇怪的问题,我刚刚开始学习信号,问题是我无法在本地PC上运行它的应用程序给出了错误说明找不到集线器,但此应用程序正在服务器上运行!下面是一个类,名称为StatusMessageHubProxy:

 public class StatusMessageHubProxy
{
    private static HubConnection connection = new HubConnection(WebConfigurationManager.AppSettings["StatusMessageHubURL"]);
    private static IHubProxy statusMessageHub = connection.CreateHubProxy(WebConfigurationManager.AppSettings["StatusMessageHubName"]);


    private static ILog logger = LogManager.GetCurrentClassLogger();

    /// <summary>
    /// Send update to status message hub so that all clients can update.
    /// </summary>
    /// <param name="data">ID of the turbine which sent the status change event.</param>
    public static void Update(string data)
    {
        try
        {
            connection.Start().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    logger.ErrorFormat("Could not connect to hub {0}", task.Exception.GetBaseException(), connection.Url);
                }
                else
                {
                    if (connection.State == ConnectionState.Connected)
                    {
                        // Invoke update method on hub
                        statusMessageHub.Invoke("Update", data).ContinueWith(invokeTask =>
                        {
                            if (invokeTask.IsFaulted)
                            {
                                logger.Error("Error invoking update method on hub.", invokeTask.Exception.GetBaseException());
                            }
                        });
                    }
                    else
                    {
                        logger.Error("Connection was not open, could not invoke method on hub.");
                    }
                }
            });
        }
        catch (Exception e)
        {
            logger.Error("Error sending update to status message hub.", e);
        }
    }
}

在webconfig中,我有这个:

 <appSettings>
<add key="StatusMessageHubURL" value="http//localhost/appname/signalr/hubs"/>
<add key="StatusMessageHubName" value="statusMessageHub"/>

在这里,我有错误:

 $.connection.hub.start().done()

连接中没有集线器,这就是为什么我抛出错误,知道吗?

0 个答案:

没有答案