2015-05-27 46 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