Windows Phone 7 – Toast Notification Using Windows Azure Cloud Service

转载 2011年01月24日 10:12:00

Download - 78.4 KB



In this post I am going to show the step by step approach to create the Toast Notificaton on Wndows Phone7.

Before that you need to understand what is Microsoft Push Notification, to understand Windows Phone 7 notifications and flow please go through my earlier post from the below link

Microsoft Push Notification in Windows Phone 7 - In Code Project

Please Go Through The 2 Minutes ToastNotification Youtube Demo 


MyCloudService - Windows Azure Cloud Service With WCF Service Web Role

First Let us start by creating the “Windows Azure Cloud Service with WCF Service Web Role” Start Visual Studio 2010 with (UAC Account)


In the menu File->New->Projects Choose the project templete “Windows Azure Cloud Service” and name it as MyCloudService accordingly.

In the new Cloud Service project dialog, select the WCF Service web role and add to cloud service solution list and Click on Ok button.


In the IService1.cs interface file just clear the auto generated code related to Composite type that is [DataContract] and methods that is [OperationContract] and create 2 interface methods [OperationContract] as shown below… One is to subscribe from windows phone 7 and other is used to sendNotification from WPF Application.

Create the class DeviceRef ChannelURI with public property.

In the Service1.svc.cs file we need to implement interface methods. below is the complete code

Build the Windows Azure Cloud Service project and run. On the system tray the below icon will appear related to cloud development fabric and development storage.


Verify the IP address with port in the development fabric.


The browser will be launched with same IP address and port number, please provide the servicename for example service1.svc at the end of the url if Service1.svc is not found.


Now the “Windows Azure cloud service with WCF web role” is ready to serve.

WpfAppNotificationComposer - WPF Application To Send Notification

Second Let us create the new project “WPF Application to send Notification”

Create new WPF Application with the name “WPFNotificationComposer” as shown below


Go to reference in the solution explorer and right click on that and choose Add Service Reference… In the popup menu as shown below.


In the Add Service Reference Dialog, Enter the URL of the cloud service in the Address:, in this case it is

Give the name to the Namespace: ServiceReference1 
Click on Go button and then Click on Ok button once the Service1 is listed as below in the Services:.

In the MainWindow.xaml just add 4 controls, label,textbox,button and listview and design as shown below.


Below is the complete MainWindow.xaml code

MainWindow.xaml.cs created a class ToastStatus and created a Service1Client object for cloud service. and on the send button click event called the cloud service and added the status to listview accordingly.

Just build and Run the project.

Now the “WPF Application to send notification” is ready to Compose & Send toast message.

WindowsPhoneToast – Windows Phone Application To Receive Notification

Third and finally Let us create the new project “Windows Phone Application to receive notification”

Start Visual Studio 2010 as administrator (UAC Account)

In the new projects templete choose the “Windows phone Application”
name it as “WindowsPhoneToast” and click on Ok button.

Add service reference Cloud Service in the same way we added in the WpfAppNotificationComposer project, Give the name to the Namespace:MyCloudServiceReference1

In the app.xaml.cs add the following reference

In the public App() constructor just add the notification related code below InitializePhoneApplication();

Add the following event handlers accordingly

We are done with the coding now launch the the windows phone 7 app on the emulator.

While running the this Windows Phone 7 Application, it will generate the unique URI from Microsoft Cloud Service as shown below and also it will subscribe the unique URI generated from Microsoft Cloud Service to the cloud service written above. and if cloud service created above is not running we have to first launch the cloud service created above.


Once the application is running on the Emulator we have to pin the windows phone application to the start/home screen. please go through my earlier post.

How to Pin/Un Pin applications to Start/Home Screen on Windows Phone 7/Tiles on Windows Phone 7

Stay in the start page of the windows phone 7 after pinning the WindowsPhoneToast application.

Now run the ToastComposer – the WPF application created above

Enter the toast message and click on send button


To understand the status please go through the
Push Notification Service Response Codes for Windows Phone from MSDN

Now go back to the Windows Phone 7 Emulator and verify the toast message, even when application is not running we are able to receive the toast if the application is pinned to start.


Thank You :)


Initial Posting 10th December 2010.

My Other Posts In CodeProject

Please Go Through The Related Post From The Below Link
Microsoft Push Notification in Windows Phone 7

WPF based articles are as follows...
( WPF, C# ) 216 Web Safe Colors On Rotating 3D Cube using Dynamic/Generic and Relative color pallet.

( WPF, XAML, C# ) WITIYMIWYG - What Is There In Your Mind Is What You Get - Wizard. - In English and Kannada, With Simple Animations.








This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Preparing for Application and Service Deployment-Adding an HTTPS Endpoint to a Windows Azure Cloud [Update: W...

Building Windows Phone Applications Using Windows Azure

Windows Phones provide many opportunities for developers to build great applications. Nevertheless, ...

Windows Azure Service Bus - Bridge of Azure And Private Cloud

微软在Windows Azure上提供了完整的公有云解决方案,但对于很多企业来说,短时间内难以把所有的应用迁移到公有云上。已经迁移到公有云的应用和企业内部的私有云形成的混合云成为了众多企业应用的IT模...

研究人员将Windows Phone 7和Windows Azure推广到平流层的大气污染研究中

公告    :本博客为微软云计算中文博客  的镜像博客。   部分文章因为博客兼容性问题  ,会影响阅读体验  。如遇此情况,请访问  原博客。这项创新的科学技术如何在科学研究中使用呢?来自南安普顿大...

Windows Azure云计算平台将支持iphone,android,Windows phone7

微软正在把它的Windows Azure云服务定位于为包括苹果iOS和谷歌安卓在内的移动设备提供后台服务的平台。微软正在通过推出Windows Azure设备工具集来实施这个计划。这个工具集包括本地库...

使用 Windows Azure 和 Windows Phone 7 构建数据驱动的应用程序

在过去 30 年,我们经历了计算机硬件行业的爆炸式增长。从大型机到台式机再到手持设备,虽然硬件的体积缩小了,但功能却越来越强大。开发人员在某种程度上有点被计算能力的这种持续增长宠坏了,现在他们希望自己...
  • dncts
  • dncts
  • 2011年01月30日 14:26
  • 1052

ISV客户博客系列:Windows Azure上的Softlibrary 和 Kern4Cloud

编者按:本博客出自Softlibrary的首席技术官Miguel Parejo之手,描述了该公司是如何使用Windows Azure 和 Windows Azure Marketplace运行和出售其...

Designing Data Storage Architecture-Using the Windows Azure Storage Services The Windows Azure storage services provide ...

公开发布版的Windows Azure 基础结构服务中的 SQL Server – 文档和最佳实践(已更新),还有即将发布的博客

一周前,WindowsAzure 刚刚宣布公开发布版的基础结构服务正式推出, 这标志着WindowsAzure从此开始完全支持基础结构即服务,SQL Server是其中的一个主要组件。 预安装的...

Windows Azure 革新 – 欢迎来到VS2012

当微软发布第一个预览版的Windows 8和Visual Studio,社区里很多人在问,windows azure tool是否可用?答案是“否”。微软承诺windows azure tool(目前...
您举报文章:Windows Phone 7 – Toast Notification Using Windows Azure Cloud Service