我有两个集线器,我正在尝试从服务器建立到它们的两个连接:
var hubConnection1 = new HubConnection("http://localhost:14382");
var proxy1 = hubRestaurantConnection.CreateHubProxy("Hub1");
hubConnection1.Start().Wait();
var hubConnection2 = new HubConnection("http://localhost:14382");
var proxy2 = hubConnection.CreateHubProxy("Hub2");
hubConnection2.Start().Wait();
hubConnection2.Start().Wait() 调用总是崩溃并出现异常:
StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Transfer-Encoding: chunked
X-SourceFiles: =?UTF-8?B?QzpcZGV2XHdlYjJcRmxpcGRpc2hXZWJcRmxpcGRpc2guV2ViXHNpZ25hbHJcc3RhcnQ=?=
Cache-Control: private
Date: Wed, 27 May 2015 15:19:49 GMT
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Type: text/html; charset=utf-8
}
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: Microsoft.AspNet.SignalR.Client.HttpClientException: StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Transfer-Encoding: chunked
X-SourceFiles: =?UTF-8?B?QzpcZGV2XHdlYjJcRmxpcGRpc2hXZWJcRmxpcGRpc2guV2ViXHNpZ25hbHJcc3RhcnQ=?=
Cache-Control: private
Date: Wed, 27 May 2015 15:19:49 GMT
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Content-Type: text/html; charset=utf-8
}
我之所以有两个集线器,是因为一个给有管理员权限的用户使用,第二个给其他用户使用,它有不同的方法。
来自 javascript 客户端的连接似乎工作正常。我知道集线器共享一个连接,但从我的设计角度来看这没有问题。是错误还是我做错了什么?
我也试过交换创建集线器代理的顺序,但异常只发生在同一个代理上。
最佳答案
您使用相同的 HubConnection 创建多个 hubproxies:
var hubConnection = new HubConnection("http://localhost:14382");
var proxy1 = hubConnection.CreateHubProxy("Hub1");
var proxy2 = hubConnection.CreateHubProxy("Hub2");
hubConnection.Start().Wait();
关于c# - Signalr 创建到两个不同集线器的两个连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30486789/