I have an Azure Signal R service running in Default mode.
I have a process that runs in a long-running durable function. When this process completes, I want to send a message to a group of users via my Azure Signal R service. We need to send via the Azure service because we use Azure Front Door, which currently blocks web socket requests. Our blazor app is already connected to and using the Azure signal R service, so it cannot be changed to serverless.
I have a blazor app in .Net 9 where I have created a hub to watch for messages.
The problem I have is that every time I run StartAsync() on the hub connection, I am getting a 400 response with no details as to why.
This is my Hub
public class AdvisorMessagesHub : Hub<IAdvisorMessagesHub>{ public async Task SendTestMessage(string name, string message) { Console.WriteLine($"### - [{Context.ConnectionId}] Send Test Message [{name}]: {message}"); await Clients.All.ReceiveTestMessage(name, message); } public async Task JoinAdvisorGroupAsync(long advisorId) { Console.WriteLine($"### - [{Context.ConnectionId}] Join Advisor Group [{advisorId}]"); await Groups.AddToGroupAsync(Context.ConnectionId, advisorId.ToString()); }}In my signal R hub service, here is the method that initializes my hub connection.
private HubConnection InitializeAzureSignalR() { try { var serviceUtils = new ServiceUtils(_configService.GetConfigurationValue(ConfigurationConstants.ConfigurationKeys.SignalR.SignalRConnectionString)); var url = GetClientUrl(serviceUtils.Endpoint, SignalRHubConstants.HubNames.AdvisorMessages); var connection = new HubConnectionBuilder() .WithUrl(url, option => { option.AccessTokenProvider = () => { return Task.FromResult(serviceUtils.GenerateAccessToken(url)); }; }) .ConfigureLogging(config => { config.SetMinimumLevel(LogLevel.Error); }) .WithAutomaticReconnect() .Build(); return connection; } catch (Exception e) { _logger.WriteException(e, "Error during connection to Azure SignalR Service"); throw; } } private string GetClientUrl(string endpoint, string hubName) { return $"{endpoint}/client/?hub={hubName}"; }ServiceUtils was pulled from the examples. _configService is just pulling a value from configuration that's holding the signalr connection string.
The failure happens when I try to open a connection:
public async Task BeginMonitoringAsync(CancellationToken cancellationToken = default) { if (_connection.State == HubConnectionState.Disconnected) { await _connection.StartAsync(cancellationToken); } }The error that is thrown when StartAsync is called is
Response status code does not indicate success: 400 (Bad Request).