'Getting SignalR Client to work with Azure SignalR Server

I have inherited an Azure SignalR Web API app written in ASP.NET Core 5, and I'm having trouble creating a client that works with it. I'm new to SignalR. Also, this Azure SignalR server has not been used in production, so I can't guarantee that my problem isn't with it.

Here's the SignalR related bits of the Server:

In Startup.cs

services.AddSignalR().AddAzureSignalR( Configuration.GetConnectionString( "SignalRConnectionString" ) );

and this:

app.UseEndpoints( endpoints =>
            {
                endpoints.MapHub<PushSignalBroadcastHub>( "/pushsignalhub" );
                endpoints.MapControllers();
            } );

My Hub (a snippet of it):

public class PushSignalBroadcastHub : Hub
    {
        private readonly ILogger<PushSignalBroadcastHub> _logger;

        public PushSignalBroadcastHub( ILogger<PushSignalBroadcastHub> logger )
        {
            //  _context = connectionsData;
            _logger = logger;
        }

        public override Task OnConnectedAsync()
        {
            // wait until login to add the connection to the table 
            return base.OnConnectedAsync();
        }

        public override async Task OnDisconnectedAsync( Exception exception )
        {
            await base.OnDisconnectedAsync( exception );
        }

        public async Task<bool> RelayToGroup( string groupId, string method, string jsonData )
        {
            try
            {
                await this.Clients.Group( groupId ).SendAsync( method, jsonData );
            }
            catch ( Exception ex )
            {
                _logger.LogError( ex, $"Failed to relay message {method} to client {groupId}, Error: {ex.Message}" );
            }
            return true;
        }

Here's my client code:

_connection = new HubConnectionBuilder()
     .WithUrl( new Uri( "https://my-azure-api-appservice-url/pushsignalhub" ) )
     .Build();
                
     bool result = await _connection.InvokeAsync<string>( "RelayToGroup", "1234", "Test", "somejson" );

When I try to connect, _connection.State is always Disconnected.

When I connect, should I specify the URL of my deployed app service on azure or the endpoint in the appSettings? I assume it's the app service, which I did in this example.

I assume there's something I'm missing, but I'm at a loss here. Any help would be appreciated.

UPDATE

I get the following exception. I've heard there are issues with TLS that cause this, but I haven't been able to find a solution that works.

    System.Net.WebSockets.WebSocketException
  HResult=0x80004005
  Message=Unable to connect to the remote server
  Source=System.Net.WebSockets.Client
  
Inner Exception 1:
HttpRequestException: The SSL connection could not be established, see inner exception.

Inner Exception 2:
IOException: Cannot determine the frame size or a corrupted frame was received.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source