Notification Hubs
Notification Hub is introduced to manage the push notification in the human interface devices such as smartphones, Tablets and Desktops etc.
Notification Hubs use a full multiplatform, scaled-out push notification infrastructure, and considerably reduce the code that runs in the app backend. The following are some of the advantages using notification Hubs.
Multiple platforms
Supports for all major mobile platform such as Windows Store, iOS, Android, and Windows Phone apps for sending a push notification
Works with any backend
.NET, PHP, Java, Node, etc.
Scale
Notification hubs scale to millions of devices without the need of changes.
Rich set of delivery patterns
Broadcast – for all devices.
Unicast/Multicast – for a specified device.
If you are new to notification Hubs. I recommend reading Notification Hubs in Azure.
To complete this article following are the requirement you should have.
- Visual Studio 2015 community edition or later
- Azure Account
Let’s get started.
Open Visual Studio 2015 to create a simple console Application.
Click New Project, in the project creation wizard, select Visual C# >> Windows >> select console Application, as shown below.
Once the project creation is successful, click Tools, Click NuGet Package Manager and click Package Manager console.
This displays Package Manager console in Visual Studio 2015.
In Package Manager console, set the default project to our new console Application project and execute the command, given below.
- Install-Package Microsoft.Azure.NotificationHubs
Open the file Program.cs and add the statement, given below.
- using Microsoft.Azure.NotificationHubs;
In Program.cs file, add the method, given below.
- private static async void SendNotificationAsync()
- {
- NotificationHubClient hub = NotificationHubClient
- .CreateClientFromConnectionString("<connection string with full access>", "<hub name>");
- var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">Hello from a .NET App!</text></binding></visual></toast>";
- await hub.SendWindowsNativeNotificationAsync(toast);
- }
Note - Replace the connection string with your connection string, which is available in Azure management portal.
Replace Hub name with your Hub Name that is displayed in Azure portal.
Add the code, given below in Main Function.
- SendNotificationAsync();
- Console.ReadLine();
After the coding process completes, it means press F5 button to execute your console Application.
Now, you receive toast notification to configure Windows or Windows phone Application.
Summary
In this blog, we will see about sending a notification, using console Application.