c# - Signalr 创建到两个不同集线器的两个连接

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

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

最佳答案

您使用相同的 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/

相关文章:

c# - 将具有未知大小数组的结构从非托管代码传递到托管代码

c# - NHibernate 映射域 "extension properties"?

c# - 找不到类型或 namespace "Utilities"

.net - 在 Visual Studio 中以部分信任的方式运行 MSTest

java - SignalR Java 客户端仅支持 1.3

c# - SignalR 与 ASP.NET MVC 和 WinForms

redis - 使用 SignalR 和 Redis 的组

c# - 从 RSACryptoServiceProvider 创建 X509Certificate2 失败,找不到请求的对象

c# - 如何在 .Net 中修改 tiff 创建日期

c# - 如何使用 objectdatasource 将枚举绑定(bind)到 winform 组合框