【问题标题】:Connecting the SignalR console client to the server on Azure将 SignalR 控制台客户端连接到 Azure 上的服务器
【发布时间】:2021-04-13 02:49:53
【问题描述】:

我想使用 SignalR 部署服务器(在 Azure 上)。 和控制台客户端,以便它接受来自服务器的命令。

服务器代码取自这里:https://docs.microsoft.com/ru-ru/aspnet/signalr/overview/getting-started/tutorial-getting-started-with-signalr

此处的控制台客户端示例:https://www.codeproject.com/Articles/804770/Implementing-SignalR-in-Desktop-Applications

using Microsoft.AspNet.SignalR.Client;
using System;

namespace SignalRClient
{
    class Program
    {
        static void Main(string[] args)
        {
            IHubProxy _hub;
            string url = @"https://signalrchatmsdn20210410135946.azurewebsites.net/";
            //string url = @"http://localhost:62545";
            var connection = new HubConnection(url);
            _hub = connection.CreateHubProxy("BetHub");
            connection.Start().Wait();

            _hub.On("ReceiveLength", x => Console.WriteLine(x));

            string line = null;
            while ((line = System.Console.ReadLine()) != null)
            {
                _hub.Invoke("DetermineLength", line).Wait();
            }

            Console.Read();
        }
    }
}

如果我在本地运行服务器,一切正常 (string url = @"http://localhost:62545";) 如果我在 Azure 上运行服务器,它可以通过浏览器运行。但是控制台客户端抛出异常。 System.Net.WebException

【问题讨论】:

  • 问题可能是用于 HTTPS 连接的 TLS 身份验证。确定是否是 TLS 问题的最佳方法是使用像 wireshark 或 fiddler 这样的嗅探器并捕获连接。 TLS 在发送 HTTP 请求之前完成。因此,如果您看到请求比 TLS 良好,您需要捕获 HTTP 响应并查看状态是 200 OK 还是 400/500 失败。如果没有 HTTP 请求,则会在嗅探器中看到 TLS 版本,您需要找出浏览器工作时正在使用的 TLS 版本以及 c# 失败时使用的版本。

标签: c# signalr signalr-hub signalr.client


【解决方案1】:

jdweng 完全正确。

就我而言,更改部署设置就足够了。

TLS\SSL 设置 => 仅 HTTPS:关闭

【讨论】:

    猜你喜欢
    • 2019-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多