I have an ASP.NET Core Web API that is hosted in azure. The Web API connects to an Azure SignalR service at startup.
Then client apps (Winforms) connects to the Web API using the Azure SignalR URL like this: https://mydomain.azurewebsites.net/myhub.
However, when I run the Web API locally, and I try to connect my client, then the client app somehow gets connected to both the locally running Web API AND the Web API hosted in Azure.
I know this because the Web API has a function where it periodically sends out heartbeat to connected clients.
And my client is getting 2 of these heartbeats.
In the client app, I connect to the locally running Web API like this:
hubConnection = new HubConnectionBuilder()
.WithUrl(@"http://localhost:5000/MyHub")
.Build();
How can I force my Winforms client app to only connect to the locally running Web API?
Your local and prod web apps connect to Azure SignalR with the same Hub name, all the connected app servers are considered to be instances of the same application which cause the issue.
To fix the issue, you can try to specify
ApplicationNameoption, like below.For more details, please check this doc: https://github.com/Azure/azure-signalr/blob/dev/docs/run-asp-net-core.md#applicationname