Introduction
In my previous article , we learned about how to setup the SignalR Service in Azure Portal. In this article, we will develop the SignalR client applications to connect to Azure SignalR Service to do real time communication between cross platform devices. We are going to develop the following applications.
Web App SignalR Client App
This is an Asp.net Core Web Application with layout defined using bootstrap library. In the landing page, we will be adding DIV container to show all the incoming messages from SignalR Hub and in the bottom of the page, we will place the text box and button to publish the text message to other clients. We will use the SignalR Javascript Client library to connect to SignalR Hub.
Steps
Launch the Visual Studio and Create a New Project (.Net Core -> Asp.net Core Web Application) . You must have the latest .Net Core SDK (2.1) installed on your machine.
In my previous article , we learned about how to setup the SignalR Service in Azure Portal. In this article, we will develop the SignalR client applications to connect to Azure SignalR Service to do real time communication between cross platform devices. We are going to develop the following applications.
- .Net Core We App to send and receive the data from the browser.
- .Net Framework (v4.6.1) based windows forms application that running in system tray with the global hot key registered (CTRL + SHIFT + C) to push the clipboard content to other devices whenever the hotkey is pressed.
- Xamarin based Android App to receive the data from SignalR Hub in Local Notification Window.
This is an Asp.net Core Web Application with layout defined using bootstrap library. In the landing page, we will be adding DIV container to show all the incoming messages from SignalR Hub and in the bottom of the page, we will place the text box and button to publish the text message to other clients. We will use the SignalR Javascript Client library to connect to SignalR Hub.
Steps
Launch the Visual Studio and Create a New Project (.Net Core -> Asp.net Core Web Application) . You must have the latest .Net Core SDK (2.1) installed on your machine.

Install the Microsoft.Azure.SignalR Nuget Package for your project.

By default, the Microsoft.AspNetCore.SignalR package contains its server libraries as part of its ASP.NET Core Web Application template. However, the JavaScript client library for SignalR must be installed using npm. Use the following commands from Node Package Manager Console to install it and copy the signalr.js file from node_modules\@aspnet\signalr\dist\browser to wwwroot\lib\signalr\signalr.js. (Create a SignalR Folder under Lib Directory)
Windows Forms App SignalR Client
This is a full .net framework based windows forms app that will be running in the system tray with the registered global hotkey CTRL + SHIFT + C. Whenever hot key is pressed anywhere in the desktop, app will check and publish the content of the clipboard to other clients. I used NHotKey open source library for registering the hotkey in Windows Forms.
- npm init -y
- npm install @aspnet/signalr
We will create a new hub called MagicPasteHub that internally connects to Azure Service. Right click on the Project in Solution Explorer and Create a New Folder called Hub and then add a new file called MagicPasteHub.cs and paste the following code.
- publicclass MagicPasteHub: Hub {
- public async void SendData(string data) {
- await Clients.All.SendAsync("ReceiveData", data);
- }
- }
In the Startup.cs, add the following code in ConfigureServices method. SignalREndPoint Key will hold the Azure Endpoint Value. During Development time, you can store the Azure Endpoint Values in UserSecrets.json. The method AddAzureSignalR will establish the link between Web App and Azure SignalR library using the EndPoint URL.
- services.AddSignalR().AddAzureSignalR(Configuration["AppSettings:SignalREndPoint"])
- .AddHubOptions<magicpastehub>(a => a.EnableDetailedErrors = true);
Add the following code in Configure Method to map the AzureSignalRService with MagicPasteHub Route URL
- app.UseAzureSignalR(routes => {
- routes.MapHub < magicpastehub > ("/MagicPaste");
- });
In the site.js, add the following code to setup the signalR client to connect to hub and wire up the button click event to send the message and wire up the ReceiveData event to append the incoming data into DIV container.
- const connection = new signalR.HubConnectionBuilder().withUrl("/MagicPaste").build();
- connection.start();
- $("#btnPublish").click(function() {
- var msg = $("#inputData").val();
- if (msg.length > 0) {
- connection.invoke("SendData", msg).catch(err => console.error(err.toString()));
- $("#inputData").val('');
- }
- });
- connection.on("ReceiveData", (msg) => {
- $("#messagesList").append($(" < li class = "list-group-item list-group-item-info" > ").html(msg));
- });
- $('#inputData').keypress(function(event) {
- if (event.keyCode == 13) {
- $('#btnPublish').click();
- }
- });
The User Interface of the web app will look like below. I have hosted this app into Azure with Free Tier Resource Group. You can follow the microsoft official docs for how to publish web app into Azure Portal.
Windows Forms App SignalR Client
This is a full .net framework based windows forms app that will be running in the system tray with the registered global hotkey CTRL + SHIFT + C. Whenever hot key is pressed anywhere in the desktop, app will check and publish the content of the clipboard to other clients. I used NHotKey open source library for registering the hotkey in Windows Forms.




soofian ahmedPosted Feb 12, 2019, 4:54 AM
Microsoft.Azure.SignalR 1.0.0-preview1-10015 in your web application is not connecting to client apps. When I install Microsoft.Azure.SignalR -Version 1.0.6, it works.
praveen mPosted Nov 20, 2018, 9:31 AM
Hi, Can we use signalr client library in Hybrid mobile App? I used following NPM package https://www.npmjs.com/package/@aspnet/signalr but its throwing following error “Failed to complete negotiation with server: SyntaxError: JSON Parse error: Unexpected identifier object”.
prashant rawatPosted Oct 6, 2018, 5:54 AM
Sir can we use signal r with android studio app is signalR fesiable?