Overview

Overview

WP7 application can’t run in the background (performance, battery life, usage of radio) and therefore there is a need to have a mechanism that facilitates a communication channel between backend services and application on the phone. Push Notification is the mechanism through which backend services can send “messages” to the phone to notify the user for any state changes. The Push Notification service is designed to provide a cloud service with a dedicated, resilient, and persistent channel for pushing a notification to a mobile device.

Figure 1 Push Notifications

When a cloud service needs to send a push notification to a device, it sends a notification request to the Push Notification service, which in turn routes the notification to the application, or to the device as a toast or tile notification, depending on the type of notification that is sent.

The Push Client on the device receives push notifications through a notification channel. When the channel is created, a subscription is also created which allows the cloud service to push notifications to that channel. A channel is represented by a URI which contains all of the information associated with the subscription.

Once an application receives the push notification, it can access the cloud service using the cloud service’s protocol to retrieve any needed information.

Since, applications today tends to share multiple screens running on local computer, in the cloud and on the phone. The push notification services, enables seamless integration between all three with a simple and unified API.

This lab covers the push notification and also introduces the usage of http services in Silverlight. During this lab you will create server side logic needed to send messages through Push Notification Service. You will create a simple Windows Phone 7 application which serves as a client to receive such notifications. The client application will receive weather updates. The server side business application (simple WPF application) will send weather alerts to registered client applications through Push Notification Services. Once client Windows Phone 7 application will receive such alert it will display received information.

Objectives

At the end of the lab you will:

  • Familiarize with the communication capabilities of Windows Phone 7 application
  • Familiarize with the push notification concepts and the behaviors they enable on the phone
  • Understand how push notification works on the phone and in the cloud
  • Use the phone push notification services to create a subscription for Tokens (tiles), Toasts, and raw push notification
  • Use web client to register for Push Notifications
  • Use the network status to display the current status of the phone network
  • Create a SL application that register for push notification services (both token and toast)
    • Handle push events (token, toast, and raw)during run time
    • Show token and toast on shell

Prerequisites

The following is required to complete this hands-on lab:

  • Microsoft Visual Studio 2010 Express for Windows Phone or Microsoft Visual Studio 2010
  • Windows Phone Developer Tools
    Note:
    All of these Tools can be downloaded together in a single package from http://developer.windowsphone.com

Setup

For convenience, much of the code used in this hands-on lab is available as Visual Studio code snippets. To install the code snippets:

  1. Run the .vsi installer located in the lab's Source\Setup folder.
    Note:
    If you have issues running the code snippets installer you can install the code snippets manually by copying all the .snippet files located in the Source\Setup\CodeSnippets folder of the lab to the following folder: My Documents\Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets

Using the Code Snippets

With code snippets, you have all the code you need at your fingertips. The lab document will tell you exactly when you can use them. For example,

Figure 2 Using Visual Studio code snippets to insert code into your project

To add this code snippet in Visual Studio, you simply place the cursor where you would like the code to be inserted, start typing the snippet name (without spaces or hyphens), watch as IntelliSense picks up the snippet name, and then press the Tab key twice when the snippet you want is selected. The code will be inserted at the cursor location.

Figure 3 Start typing the snippet name

Figure 4 Press Tab to select the highlighted snippet

Figure 5 Press Tab again to expand the snippet

To insert a code snippet using the mouse rather than the keyboard, right-click where you want to insert the code snippet, select Insert Snippet followed by My Code Snippets and then pick the relevant snippet from the list.

To learn more about Visual Studio IntelliSense Code Snippets, including how to create your own, see http://msdn.microsoft.com/en-us/library/ms165392.aspx.

Exercises

This hands-on lab comprises the following exercises:

  1. Introduction to the Windows Phone RAW notifications for Updates
  2. Introduction to the Toast and Tile Notifications for Alerts

Estimated time to complete this lab: 90 minutes.