Get started with Notification Hubs
This topic shows you how to use Azure Notification Hubs to send push notifications to a Windows Phone 8 application. 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.
This tutorial walks you through the following steps to enable push notifications:
- Create your Notification Hub
- Connecting your app to the Notification Hub
- Send notifications from your back-end
The tutorial demonstrates the simple broadcast scenario using notification hubs. Be sure to follow along with the next tutorial to learn how to use notification hubs to address specific users and groups of devices. 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.
This tutorial uses MPNS in unauthenticated mode. MPNS unauthenticated mode comes with restrictions on notifications you can send to each channel. Notification Hubs support MPNS authenticated mode.
Connecting your app to the Notification Hub
In Visual Studio, create a new Windows Phone 8 application.
Add a reference to the Azure Messaging library for Windows Store using the WindowsAzure.Messaging.Managed NuGet package. In the Visual Studio menu, click Tools, then Library Package Manager, then Package Manager Console. Then, in the console window type:
and press Enter.
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.
Send notification from your back-end
You can send notifications using notification hubs from any back-end using the REST interface. This tutorial sends notifications with a .NET console app, and with a Mobile Service using a node script.
To send notifications using a .NET app:
Create a new Visual C# console application:
Add a reference to the Azure Service Bus SDK with the WindowsAzure.ServiceBus NuGet package. In the Visual Studio main menu, click Tools, then Library Package Manager, then Package Manager Console. Then, in the console window type:
and press Enter.
Open the file Program.cs and add the following
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 insert the name of your hub and the connection string called DefaultFullSharedAccessSignature that you obtained in the section "Configure your Notification Hub." Note that this is the connection string with Full access, not Listen access.
Then add the following line in your Main method:
Press the F5 key to run the app. You should receive a toast notification. Make sure to have your Windows Phone emulator running and your app closed.
You can find all the possible payloads on MSDN in the toast catalog, and tile catalog.
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.