Windows Phone 7 – Toast Notification Using Windows Azure Cloud Service

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

Download ToastNotification_Src.zip - 78.4 KB

Introduction

Toast.png

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 

youtube_small.png

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)

RunAsAdministrator.png

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

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.

5_3.png

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.

Azure.png

Verify the IP address with port in the development fabric.

DevelopmentFabricSmall.png

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.

AzureInBrowserSmall.png

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

WPFNotificationComposer.png

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

WPF_SolExp_Reference.png

In the Add Service Reference Dialog, Enter the URL of the cloud service in the Address:, in this case it is http://127.0.0.1:81/Service1.svc

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:.
WPF_AddServiceReference.png

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

ComposerDesign.png


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.
NewProjectPhone.png

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.

OutputWindowVS2010WP7.png

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

PuchNotificationComposer.png

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.

PushNotification.png

Thank You :)

History

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.

 

 

 

 

 

 

License

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

分布式系统论文

作者:严林 链接:https://www.zhihu.com/question/30026369/answer/46476717 来源:知乎 著作权归作者所有。商业转载请联系作者获得授权,非商业...
  • u012149181
  • u012149181
  • 2017年12月28日 21:15
  • 23

Azure学习笔记:Cloud Service(4)

Cloud Service中包含两类角色:WebRole和WorkerRole。这些Roles们可以理解为不同的虚拟机,唯一的区别即为:WebRole用来寄宿Web站点,可以把它理解为一台安装了IIS...
  • ghostbear
  • ghostbear
  • 2014年03月20日 14:57
  • 4919

使用Azure媒体服务对现场活动进行直播

本文介绍以下三方面内容: 搭建直播系统所需的组件,以及每个组件的功能。 一次直播活动的流程,包括准备工作,进行中和活动结束。这里给出建议的步骤,供读者参考。 直播在Azure中产生的费用。 1. ...
  • AzureIncubationChina
  • AzureIncubationChina
  • 2015年07月01日 17:01
  • 1597

记录下用Windows Azure PowerShell命令工具的使用历程

使用远程命令方式操作windows azure云服务,那就需呀用到PowerShell,这也是平台管理员不可缺少的利器,不单一依赖Web Platform网页形式管理,PowerShell是一种命令行...
  • qq_21785607
  • qq_21785607
  • 2015年03月03日 09:09
  • 1324

初学者的福音——在Visual studio中使用Azure例子程序(.NET)

Visual Studio里面使用Azure例子程序
  • ShaunFang
  • ShaunFang
  • 2013年11月14日 10:39
  • 2735

设置Windows phone 手机真机调试

最近要做Widows phone开发,用的最新的8.1的API,所以手机由8.0升级到了8.1,从网上查了下教程,做个记录! 1.首先,我们点击手机自带的应用商店 -->搜索软件“升级到WP8...
  • u010004082
  • u010004082
  • 2015年02月17日 21:52
  • 977

Windows phone 7之生命周期

原文地址:http://www.cnblogs.com/xiaogeer/archive/2012/04/08/2437186.html WP7的生命周期一般说的是整个应用程序的声明周期,而不注...
  • zhaogengzi
  • zhaogengzi
  • 2014年01月16日 14:18
  • 544

最全的Windows Azure学习教程汇总

本文整理了丰富的 Windows Azure 学习资源,帮助开发者全面地学习 Windows Azure 知识,并将 Windows Azure 运用在项目和实际工作中。...
  • powertoolsteam
  • powertoolsteam
  • 2016年11月08日 15:25
  • 4726

AWS和Azure的比较(1)

全球领先的云的计算平台主要有两个,一个是Amazon Web Service,另外一个则是Microsoft Windows Azure,他们都同时提供了大量的和云计算相关的资源,包括计算,存储,网络...
  • iamdll
  • iamdll
  • 2016年02月15日 13:55
  • 2134

Windows Phone8模拟器设置

一、Windows Phone8 sdk 下载链接 http://dev.windowsphone.com/zh-cn/downloadsdk 系统要求 •操作系统类型:  Windo...
  • cometwo
  • cometwo
  • 2013年04月19日 23:15
  • 1405
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Windows Phone 7 – Toast Notification Using Windows Azure Cloud Service
举报原因:
原因补充:

(最多只允许输入30个字)