I have the Following Code for my SignalR Client. Based on my knowledge so far, this code should print anything that is send by "noitfyQueuePosition" event.
using Microsoft.AspNetCore.SignalR.Client;
Console.WriteLine("Connecting to Hub...");
var hubConnection = new HubConnectionBuilder().WithUrl("https://localhost:7178/queueHub").Build();
hubConnection.Closed += async (error) =>
{
Console.WriteLine("Connection closed. Reconnecting...");
await Task.Delay(new Random().Next(0, 5) * 1000);
await hubConnection.StartAsync();
};
hubConnection.On<string>("notifyQueuePosition", (queueCount) =>
{
Console.WriteLine($"Message received from server: {queueCount}");
});
try
{
await hubConnection.StartAsync();
Console.WriteLine("Connected to SignalR Hub.");
await hubConnection.InvokeAsync("JoinQueue", "fj294ij29r8jv09258jwr0fj2508f2trvjh2");
}
catch (Exception ex)
{
Console.WriteLine($"Error connecting to SignalR Hub: {ex.Message}");
}
Console.ReadLine();
I'm using an instance of my hub in another class and using the following method to send queue count to every connection in my server. "await _queueHub.Clients.All.SendAsync("notifyQueuePosition", queueCount);"
The problem is that Queue Count isn't getting printed on my Client's Console.
I create a background service and reproduced your issue, and I get the error like below. The error maybe same as your side, if not, please check the Suggestion below, it my help you to print the more details like my picture.
Then I add the
Newtonsoft.Jsonpackage and format the data, then fix the issue.Like below
Here is my full code.
Success Picture
Suggestion
We need to enable the signalr client logging to check the detailed message.