2015-05-27 40 views
2

我有两个集线器,我试图从服务器建立他们两个连接:Signalr创建两个连接到两个不同的轮毂

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客户端连接似乎工作正常。我知道集线器正在共享一个连接,但从我的设计角度来看,这不成问题。它是错误还是我做错了什么?

我也尝试交换创建集线器代理的顺序,而异常只发生在同一个代理上。

+0

“异常只能在同一代理发生了”你的意思是第二个或'Hub2'?您是否还试图捕获服务器端生成的错误? – Guvante

+0

是的,它只发生在同一个代理(Hub2)上。我没有发现错误。 – user1841935

回答

0

可以使用相同的HubConnection创建多个hubproxies:

var hubConnection = new HubConnection("http://localhost:14382"); 
var proxy1 = hubConnection.CreateHubProxy("Hub1"); 
var proxy2 = hubConnection.CreateHubProxy("Hub2"); 
hubConnection.Start().Wait(); 
+0

非常感谢您的回复,这是真的,它可以解决问题,因为您不需要调用Start()。第二次等待()。但我现在真的不能再现这个问题。在我添加了try-catch之后,它神秘地停止了发生 - 现在我可以删除try-catch块,它可以工作.. :-( – user1841935