Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to use signalr 2 with web api, calling signalr?


Asked by Holly Bauer on Dec 11, 2021 Web Services



The best I could come up with was a solution that only answered to the API method being hit, but the clients wasn't able to fire any of the Hub's methods (they could only listen to it).
In respect to this,
Objective: Use SignalR for notification between Web API, and TypeScript/JavaScript based Web App, where Web API and the Web App is hosted in different domain. Enabling SignalR and CORS on Web API: Create a standard Web API project, and install the following NuGet packages: Microsoft.Owin.Cors Microsoft.AspNet.WebApi.Cors
Moreover, In client code, you define methods that can be called from the server, and you call methods that run on the server. SignalR takes care of all of the client-to-server plumbing for you.
Subsequently,
Deriving from the Hub class is a useful way to build a SignalR application. You can create public methods on your hub class and then use those methods by calling them from scripts in a web page. In the chat code, clients call the ChatHub.Send method to send a new message.
Additionally,
Take a look at ASP.NET Core SignalR. Visual Studio 2017 with the ASP.NET and web development workload. This section shows how to use Visual Studio 2017 and SignalR 2 to create an empty ASP.NET web application, add SignalR, and create the chat application. In Visual Studio, create an ASP.NET Web Application.