SENDING AND RESPONDING TO PUSH NOTIFICATIONS

Now that you know how the push notification architecture works and what's possible, it's time to look at some code. First, you'll look at how to register an application with the push notification framework by creating and configuring a notification channel. Next, you'll look at how to use the URI endpoint in the channel to register with a simple Representational State Transfer (REST) service that you'll create. Next, you'll look at how to use this service to send push notifications to your application and see what happens.

Creating and Configuring a Notification Channel

As you've learned, the first step in using the push notification framework is to create a notification channel in your application. This means using the HttpNotificationChannel class. To create a new channel using this class, you can call its constructor. You can either pass a single string parameter with the channel name like so:

HttpNotificationChannel notificationChannel =
   new HttpNotificationChannel(“ChannelName”);

Or you can pass two parameters, where the second is the domain of the web service that will send notifications, as follows:

HttpNotificationChannel notificationChannel =
   new HttpNotificationChannel(“ChannelName”, “www.somewhere.com”);

It's good practice to use the version with two parameters even for unauthenticated web services, although for testing with local services, you can omit it. The channel name isn't really that important. You can call it ...

Get Beginning Windows® Phone 7 Application Development: Building Windows® Phone Applications Using Silverlight® and XNA® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.