1

我面临下一个问题。我尝试连接到 SignalR 服务器。我创建 HubConnection 实例并启动连接。那是成功的。但是当我为该连接创建代理集线器时,我得到了异常。SignalR 2.2.0 版代码示例:

hubConnection = new HubConnection(inputDataContract.rootUrl + inputDataContract.defaultServicePath);
hubConnection.TraceLevel = TraceLevels.All;
hubConnection.TraceWriter = Console.Out;
hubConnection.Start().ContinueWith(task => {
            if (task.IsFaulted)
            {
                Console.WriteLine("There was an error opening the connection:{0}",
                                  task.Exception.GetBaseException());
            }
            else
            {
                Console.WriteLine("Connected");
            }

        }).Wait();

hubConnection.Stop();

上面的代码执行成功。

连接日志

但是下一段代码导致错误

hubConnection = new HubConnection(inputDataContract.rootUrl + inputDataContract.defaultServicePath);
            hubConnection.TraceLevel = TraceLevels.All;
            hubConnection.TraceWriter = Console.Out;

            hubProxy = hubConnection.CreateHubProxy("Configurator");

            hubProxy.On<EventArgs>("valueChanged", res => onValueChanged(res));
            hubProxy.On<EventArgs>("configurationStateChanged", res => onConfigurationStateChanged(res));
            hubProxy.On<EventArgs>("componentModifierChanged", res => onComponentModifierChanged(res));
            hubProxy.On<EventArgs>("attributeFeasibility", res => onAttributeFeasibility(res));
            hubProxy.On<EventArgs>("attributeModifierChanged", res => onAttributeModifierChanged(res));
            hubProxy.On<EventArgs>("calculationSummary", res => onCalculationSummary(res));
            hubProxy.On<EventArgs>("configurationError", res => onConfigurationError(res));
            hubProxy.On<EventArgs>("unhandledTaskException", res => onUnhandledTaskException(res));


            hubConnection.Start().ContinueWith(task => {
                if (task.IsFaulted)
                {
                    Console.WriteLine("There was an error opening the connection:{0}",
                                      task.Exception.GetBaseException());
                }
                else
                {
                    Console.WriteLine("Connected");
                }

            }).Wait();

            hubConnection.Stop();

错误信息

我将非常感谢任何帮助。

4

0 回答 0