Push Notifications: Lab Log

A promising lab for Push notifications on WP7 is available for download at:

http://channel9.msdn.com/Learn/Courses/WP7TrainingKit/WP7Silverlight/UsingPushNotificationsLab

If I can make it quick and dirty, I’ll post my solutions.

 

UPDATE 1:

The lab was really long and boring, took close to 5 hours. The vssnippets in the download alleviated some boredom but still tutors trying to show off on async and other “best practices” makes it hard to keep track of what is actually needed.

 

The lab worked fine for RAW notifications (notifications handled within the app, but failed in the important Tile and Toast notifications. The Xml being used was incorrect and this blog fixed that issue.

 

http://www.thisisfanzoo.com/Blog/JeffF/archive/2010/08/02/a-really-long-post-about-the-windows-phone-7-push.aspx

 

Here’s the correct XML in the NotificationSenderUtility

 

Toast Payload:

Code Snippet
  1.      var toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
  2. "<wp:Notification xmlns:wp=\"WPNotification\">" +
  3.    "<wp:Toast>" +
  4.       "<wp:Text1>{0}</wp:Text1>" +
  5.       "<wp:Text2>{1}</wp:Text2>" +
  6.    "</wp:Toast>" +
  7. "</wp:Notification>";
  8.  
  9.      toastMessage = string.Format(toastMessage, text1, text2);
  10.  
  11.      byte[] payload = System.Text.Encoding.UTF8.GetBytes(toastMessage);

Tile Payload:

 

Code Snippet
  1.      var tileMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
  2. "<wp:Notification xmlns:wp=\"WPNotification\">" +
  3.    "<wp:Tile>" +
  4.       "<wp:BackgroundImage>{0}</wp:BackgroundImage>" +
  5.       "<wp:Count>{1}</wp:Count>" +
  6.       "<wp:Title>{2}</wp:Title>" +
  7.    "</wp:Tile> " +
  8. "</wp:Notification>";
  9.  
  10.      tileMessage = string.Format(tileMessage, backgroundImageUri, count, title);
  11.  
  12.      var payload = System.Text.Encoding.UTF8.GetBytes(tileMessage);
  13.      return payload;

 

BTW, the code snippets new look is thanks to the new Paste as Visual Studio Code Snippet from Windows Live Writer plugins.

Advertisements

About vijayvepa

I'm a software consultant for Software Specialists Inc. currently working at Philips Respironics, Pittsburgh

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: