Windows Push Notification service in Metro style application

Introduction

The Windows Push Notification Service is use to enable developer to send Toast, tile and badge. WNS is providing a mechanism to deliver new update to user.


Before we are going to learn Windows Push Notification I would like to describe Package.appmanifest file and its settings. This file is automatically created when you create new Metro style project. This is an XML file that can contain project configuration settings, let we have a quick look of all these setting which are in Package.appmanifest file
 
1.png

This file allow us to set four kind of settings (Application UI, Capabilities, Declarations, Packaging) as you can see in the below image. Application UI and Packaging settings are important in order to do Windows Push Notification.

2.jpg
 
[Remember] : In the above image all setting are ok but Toast capable  settings is (not set), it means our application cannot send Toast. In order to allow our application to send toast we need to set yes in place of (Not Set. Below image is shows packaging settings.
 
3.jpg

Packaging settings are allow us to set our live SDK setting, Look at the Package name , It is a place where we need to add our package name and we can get this package name after we register our application on Windows Live Dashboard, please click here  to know how to register application on Live dashboard.

Now we move back on the Push notification, Let we see how WNS server work, In order to send Toast, Tile and badge
 
4.png

 The above image showing 6 steps, let we see all these steps one by one.

  1. Metro style application uses WinRT APIs to open a new Channel URI to server, so our application sent request to Notification Client Platform.

    5.jpg
     
  2. Notification Client makes a request to WNS server and get channel URI as response.

    6.jpg
     
  3. Notification Client give this Channel URI to our metro style application

    7.png

    Any 3rd party application need to obtain its client ID (SID) and client secret in order to communicate with cloud service. In order to get application client ID (SID) and client secret we need to register our application on live Dashboard (This article is push notification vie using live SDK). Please click here to know how to register application on live dashboard.
     
  4. Metro style application send request to the Cloud server to get Authentication token.

    [Remember] we need to use Channel URI, Client Secret and Client ID (SID) in order to get access token from cloud service.
     
    8.jpg

    9.png


    OAuthToken class is just have 2 property (Access Token and Token Type), It has sated by OnAuthenticate() method.
     
  5. Cloud Service creates a request to the WNS Server by using Channel URI and Authentication Token. If everything is going very smooth then WNS   return status 200 as its response 

    10.jpg
     

    [Remember]:PushWNS() method using Notification type and Notification XML. Please look at the below table to get idea of Notification Type and Notification XML.
     

    Notification Name

    Notification Type

    Notification XML

    Badge

    "wns/badge"

    "<?xml version='1.0' encoding='utf-8'?><badge value=\"2\"/>"

    Tile

    "wns/tile"

    "<tile><visual version=\"1\"><binding template=\"TileWideText03\"> <text id=\"1\">Hello World! My tile notification</text></binding><binding template=\"TileSquareText04\"><text id=\"1\">Hello World!</text></binding></visual></tile>"

    Toast

    "wns/toast"

    "<?xml version='1.0' encoding='utf-8'?><toast><visual version='1'><binding template='ToastText01'><text id='1'>My first Toast</text></binding></visual></toast>"

     

  6. Notification Client can get this response and send it to our application.

When I was starting learning this I was confused how to verify these Badge, Tile and toast are pushed or not, so let me tell you how to verify it

  1. Badge: Once you send badge successfully, please go to win8 Dashboard and check your application. Look at the below image

    11.png
     
  2. Tile: Once you send Tile successfully, please go to win8 Dashboard and check your application. Look at the below image

    11.5.png
     
  3. Toast: Once you send Toast successfully, just wait 2-3 second you will get a popup message. Look at the below image

    12.png

If you are using my project which was attached by this article then please make sure in your machine Win8 RC was installed.

I hope This article will help you to send push notification by using metro style application.
 


Similar Articles