【问题标题】:Azure SignalR Service Connection is not activeAzure SignalR 服务连接未激活
【发布时间】:2019-01-04 13:27:44
【问题描述】:

我从 2.4.0 更新了我们的信号器包,并添加了 RunAzureSignalR 而不是 RunSignalR。在 de Startup.cs 中添加了此代码

app.Map("/signalr", map =>
{
    var hubConfiguration = new HubConfiguration
    {
        EnableDetailedErrors = true
    };

    map.RunAzureSignalR(typeof(Startup).FullName, hubConfiguration, options =>
    {
        options.ConnectionString = AppApiSettings.SignalRServiceConnectionString;
    });
});

但是当我尝试向集线器发送消息时,我得到一个异常The connection is not active, data cannot be sent to the service.。找不到任何会发生这种情况或服务无法运行的原因。

当我使用 RunSignalR(自托管)时,一切运行良好。

任何帮助将不胜感激。

【问题讨论】:

    标签: asp.net-mvc signalr-2 azure-signalr


    【解决方案1】:

    事实证明,出于安全考虑,Azure 服务仅支持 TLS1.2。 请将以下代码添加到您的 Startup 中:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    

    在 github 票证上找到了此解决方案的提示:https://github.com/Azure/azure-signalr/issues/279

    “无可用服务器”表示您的应用服务器无法连接到 Azure 服务。您可以使用以下命令从应用服务器端启用跟踪,以查看是否抛出任何错误。

    GlobalHost.TraceManager.Switch.Level = SourceLevels.Information;
    

    这里有一个示例:https://github.com/Azure/azure-signalr/blob/dev/samples/AspNet.ChatSample/AspNet.ChatSample.SelfHostServer/Startup.cs#L19

    如果你在本地调试服务器端,你也可以取消选中“Just My Code”并在任何 CLR 异常抛出时中断:

    System.Security.Authentication.AuthenticationException:“对 SSPI 的调用失败,请参阅内部异常。” - (inner) "请求的功能不受支持"

    System.ObjectDisposedException: '安全句柄已关闭'

    System.Net.WebException: '请求已中止:无法创建 SSL/TLS 安全通道。'

    System.Net.WebSockets.WebSocketException: '无法连接到远程服务器' -(内部)WebException:请求被中止:无法创建 SSL/TLS 安全通道。

    【讨论】:

      【解决方案2】:

      我最近遇到了同样的问题,即谈判与map.RunSignalR(...) 合作但不是map.RunAzureSignalR(...) 并在此处尝试accepted answer 没有解决。对于像我一样尝试接受的答案后仍然遇到此问题的任何人,我发现以下内容适用于 .NET Framework 4.6.1 项目。

      在浏览器中导航到协商链接(例如.../signalr/negotiate?clientProtocol=2.1&connectionData=...&callback=jQuery...&_=...)会给出一个

      HTTP 500:尚未连接 Azure SignalR 服务,请稍后重试

      启用来自@Youp Hulsebos 和SignalR GitHub (source) 的异常调试建议后,我发现Startup.Configure(...) 中的SignalR 注册调用引发了以下异常:

      Microsoft.Azure.SignalR.Common.ServiceConnectionNotActiveException: '连接未激活,无法将数据发送到服务。'

      LoaderException - 来自程序集“Microsoft.AspNetCore.Http.Connections.Client, Version=1.0.0.0, Culture=neutral”的“Microsoft.AspNetCore.Http.Connections.Client.HttpConnection”类型中的方法“get_Features”没有一个实现。":"Microsoft.AspNetCore.Http.Connections.Client.HttpConnection"

      在找到第二个例外并应用一些 Google-fu 后,我发现 this GitHub 问题讨论了 Microsoft.Azure.SignalR.WebSocketConnectionContext 中的 LoaderException 讨论这是因为将 Microsoft.AspNetCore.Http.Connections.Client5.0.12.0 升级到 @987654335 的结果@。

      尝试将包降级到5.0.12.0,我仍然遇到同样的问题。检查链接问题 ([dotnet/aspnetcore#38699]) 后,我将以下软件包降级为 5.0.11.0,这解决了问题:

      • Microsoft.AspNetCore.Connections.Abstractions
      • Microsoft.AspNetCore.Http.Connections.Client
      • Microsoft.AspNetCore.Http.Connections.Common
      • Microsoft.AspNetCore.Http.Features

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多