Windows Phone 7 Notification Services – Prerequisites–Part 3

  Push Notification Services
  This post is a continuation of my series on implementing Push Notification Services. image  “Phone to cloud” or “cloud to phone” – Which Direction?
Direction Technologies
Phone Initiated
  • http with request/response
  • WCF
  • OData
  • WebRequestResponse
  • SOAP, JSON, POX, ATOM
Cloud initiated
  • Push Notification Services
   
  Why can’t I just run a background process in my phone app?
  This is a great question. Here is the logic. image Well then how is my app supposed to stay current if it cannot run a background process to process the data? Well, keep reading.
  What developers want
  In the ideal scenario, developers want a “Dedicated channel to app on phone”

If you need the cloud to initiate a call to the phone

 
Push Notification Services (PNS)
  3 ways PNS works
  There are different types of notifications. Once you implement one of these types, the other 2 are trivial. The challenge is setting up the infrastructure.
Type Description
Tile notification This lets you change the main application tile on the Start experience.
Toast notification This lets you popup a message on the device even if your application is not running. But your application must be on the startup screen, which is something the app user needs to do (Pin the app to the start page)
Raw notification This lets you send raw data to the running application which you can receive via an event.
   
  Here is the high level architecture for PNS – Establishing a channel
  Your application needs to first establish a channel. A channel is used to send information and updates to a mobile application from a web service. image
  Establish a subscription
  High level diagram. Once your phone application receives the channel (just a URI), your app needs to register that uri with MyWebService.
Step Description
Step #1 - Phone app tries to find an existing channel There is a good chance that if your WP application is using MPN, a persistent channel already exists for your application. If it does exist, trying to create a new one will fail and throw an exception (NotificationChannelOpenException); therefore, it is better to start by trying to find one before attempting to create a new one.
Step #2 – Create a new channel If you didn’t find an existing channel, it is time to create a new channel.
Step #3 – Send the channel URI to your cloud service Send your channel (just a URI) to your backend cloud service the push notification channel URI that you received (see steps 1 and 2)
Find or Create Explanation
Find a channel Your WP app already had an open channel. No need to create one. Just use the one that was found
Create a channel Your WP app already DID NOT HAVE an open channel. You need to create one
   
Step #4 – Register to receive tile and toast MPN messages You need to register your WP application to get tile and toast messages. This registration creates a bind between WP shell and your application, binding your application tile to receive WP notification messages as well as toast messages.
Steps #5 – Handle incoming push notification messages Your WP app now needs to do something with the notification it received.
   
image