O'Reilly logo

Beginning Windows® Phone 7 Application Development: Building Windows® Phone Applications Using Silverlight® and XNA® by Robert Fonseca-Ensor, Karli Watson, Nick Lecrenski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required