我面临下一个问题。我尝试连接到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();
我将非常感谢您的帮助。