How to resolve SignalR Hub connection issue from Client side Javascript code
I have web application developed in .NET 5.0. This web application calls Web APIs to fetch information from SQL DB. Web and API applications are two separate applications hosted in Azure. I want to push some real time data every 2 minutes to all clients when ever any record is inserted or updated in DB. I am using SignalR in my web application to achieve this. I have added required package references on server side and signalR.js on client side. Have done all the configurations on both side.
Server side: Created a Hub class with SendMessage method. I have also used IHostedService for periodic execution and calling hub's SendMessage method from IHostedService Start event to send updated data to all Clients.
Client side: Establishing connection to the hub as
var hubConnection = new signalR.HubConnectionBuilder() .withUrl("/hub/myHub") .withAutomaticReconnect() .build() .start() .then(function () { alert('connection established!'); console.log("Hub Connection established."); }) .catch(function (err) { alert(err); return console.error(err.toString()); });; hubConnection.on("UpdateCount", (myData) => { if (myData != null) { //update value in label } });
When I run the application it is giving error: Failed to complete negotiation with the server: TypeError: Failed to fetch
Error is occurring in FetchHttpClient.js file.
Can anyone please suggest what is missing here?
Thanks.