Get started with Notification Hubs
This topic shows you how to use Azure Notification Hubs to send push notifications to a Windows Phone 8 or Windows Phone 8.1 Silverlight application. If you are targeting Windows Phone 8.1 (non-Silverlight) then refer to the Windows Universal version. In this tutorial you create a blank Windows Phone 8 app that receives push notifications using the Microsoft Push Notification service (MPNS). When complete, you will be able to broadcast push notifications to all the devices running your app using your notification hub.
Notification Hubs Windows Phone SDK does not support using WNS with Windows Phone 8.1 Silverlight apps. To use WNS (instead of MPNS) with Windows Phone 8.1 Silverlight apps, follow this sample Notification Hub - WP Silverlight tutorial which uses REST APIs
The tutorial demonstrates the simple broadcast scenario using notification hubs.
This tutorial requires the following:
Completing this tutorial is a prerequisite for all other notification hubs tutorials for Windows Phone 8 apps.
To complete this tutorial, you must have an active Azure account. If you don't have an account, you can create a free trial account in just a couple of minutes. For details, see Azure Free Trial.
Create your notification hub
Log on to the Azure Management Portal, click +NEW at the bottom of the screen.
Click App Services, then Service Bus, then Notification Hub, then Quick Create.
Type a name for your notification hub, select your desired region, then click Create a new Notification Hub.
Click the namespace you just created (usually notification hub name-ns), then click the Configure tab at the top.
Click the tab Notification Hubs at the top, then click on the notification hub you just created.
Click Connection Information at the bottom. Take note of the two connection strings.
Click the Configure tab, and then click the Enable unauthenticated push notifications checkbox in the Windows Phone notifications settings section.
You now have the connection strings required to register your Windows Phone 8 app and send notifications.
Connecting your app to the notification hub
In Visual Studio, create a new Windows Phone 8 application.
In Visual Studio 2013 Update 2 or later, you instead create a Windows Phone Silverlight application.
In Visual Studio, right-click the solution, then click Manage NuGet Packages.
This displays the Manage NuGet Packages dialog box.
This downloads, installs, and adds a reference to the Azure Messaging library for Windows using the WindowsAzure.Messaging.Managed NuGet package.
Open the file App.xaml.cs and add the following
At the following code at the top of Application_Launching method in App.xaml.cs:
var channel = HttpNotificationChannel.Find("MyPushChannel");
if (channel == null)
channel = new HttpNotificationChannel("MyPushChannel");
channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(async (o, args) =>
var hub = new NotificationHub("<hub name>", "<connection string>");
Make sure to insert the name of your hub and the connection string called DefaultListenSharedAccessSignature that you obtained in the previous section. This code retrieves the ChannelURI for the app from MPNS, and then registers that ChannelURI with your notification hub. It also guarantees that the ChannelURI is registered in your notification hub each time the application is launched.
This tutorial sends a toast notification to the device. When you send a tile notification, you must instead call the BindToShellTile method on the channel. To support both toast and tile notifications, call both BindToShellTile and BindToShellToast.
In Solution Explorer, expand Properties, open the WMAppManifest.xml file, click the Capabilities tab and make sure that the IDCAPPUSH_NOTIFICATION capability is checked.
This ensures that your app can receive push notifications.
Press the F5 key to run the app.
A registration message is displayed.
Send notification from your backend
Right-click the solution, select Add and New Project..., then under Visual C# click Windows and Console Application and click OK.
This adds a new Visual C# console application to the solution. You can also do this in a separate solution.
Right-click the , click Tools, then click Library Package Manager, then click Package Manager Console.
This displays the Package Manager Console.
In the console window, set Default project to your new console application project, then in the console window execute the following command:
This adds a reference to the Azure Service Bus SDK with the WindowsAzure.ServiceBus NuGet package.
Open the file Program.cs and add the following
In the Program class, add the following method:
private static async void SendNotificationAsync()
NotificationHubClient hub = NotificationHubClient
.CreateClientFromConnectionString("<connection string with full access>", "<hub name>");
string toast = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Text1>Hello from a .NET App!</wp:Text1>" +
"</wp:Toast> " +
Make sure to replace the "hub name" placeholder with the name of the notification hub that appears in the portal on the Notification Hubs tab. Also, replace the connection string placeholder with the connection string called DefaultFullSharedAccessSignature that you obtained in the section "Configure your Notification Hub."
Make sure that you use the connection string with Full access, not Listen access. The listen access string does not have permissions to send notifications.
Then add the following line in your Main method:
With your Windows Phone emulator running and your app closed, set the console application project as the default start up project, then press the F5 key to run the app.
You will receive a toast notification. Taping on the toast banner loads the app.
You can find all the possible payloads in the toast catalog and tile catalog topics on MSDN.
In this simple example you broadcast notifications to all your Windows Phone 8 devices. In order to target specific users, refer to the tutorial Use Notification Hubs to push notifications to users. If you want to segment your users by interest groups, you can read Use Notification Hubs to send breaking news. Learn more about how to use Notification Hubs in Notification Hubs Guidance.