本文介绍了如何使用Windows Azure的Service Bus通知中心发送推送通知Windows商店应用程序。
先来明确一下大体上要做哪些步骤:
1.申请一个Windows应用商店的应用。(每个应用都有自己的身份识别标识,不然Windows Azure也不知道要将应用推送给谁)
2.在Windows Azure中创建一个Service Bus,然后在次Service Bus下创建一个通知中心。(其实推送可以用Mobile Service下的推送,但是建在Service Bus下是有好处的。具体原因后续讲解)
3.将第一步申请的应用通过代码连接到通知中心。
4.通过后台程序向通知中心发送推送,然后你的Windows商店应用就可以收到推送了。(哈哈,这一步是很神奇的,你可以用控制台程序、Winform程序、WPF程序等等发送推送。当然也可以用Cloud Service里边的服务向通知中心添加推送等等,方法多了去了)
下边开始说正事了。
第一步:申请Window应用商店的应用。
其实这个有点小儿科了,搞微软技术开发的谁都会,就简单的说一下。
1.先起个名字
2.建一个空项目
3.将应用和商店连接起来
4.然后获取你的应用的惟一身份标识和客户端密钥
第二部:在Windows Azure中创建一个Service Bus,并在该Service Bus中创建一个通知中心
1.点击最下方的新建按钮
2.我们就建立一个名为BestAppRecommendation的名称空间
3.再建立一个名为bestapp的通知中心
4.将刚才的程序包SID和客户端密钥配置好
第三部:将自己的应用通过代码连接到通知中心
1.首先要通过NugGet添加引用WindowsAzure.Messaging.Managed
2.要用到的引用有
usingWindows.Networking.PushNotifications;
usingMicrosoft.WindowsAzure.Messaging;
usingWindows.UI.Popups;
3.在App.xaml.cs中添加如下代码
private async void InitNotificationsAsync()
{
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
var hub = new NotificationHub("<hub name>", "<connection string with listen access>");
var result = await hub.RegisterNativeAsync(channel.Uri);
// Displays the registration ID so you know it was successful
if (result.RegistrationId != null)
{
var dialog = new MessageDialog("Registration successful: " + result.RegistrationId);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
}
4.在App.cs的OnLanched()函数中添加InitNotificationsAsync();
5.不要忘了让你的程序支持Toast推送
第四步:通过后台程序向通知中心发送消息,然后你的Windows商店应用就可以获得推送了
1.建立一个控制台程序
2.通过NuGet获得WindowsAzure.ServiceBus的引用
3.添加usingMicrosoft.ServiceBus.Notifications;引用
4.在控制台程序的中添加如下函数
private static async void SendNotificationAsync()
{
NotificationHubClient hub = NotificationHubClient.CreateClientFromConnectionString("<connection string with full access>", "<hub name>");
var toast = @"<toast><visual><binding template=""ToastText01""><text id=""1"">Hello from a .NET App!</text></binding></visual></toast>";
await hub.SendWindowsNativeNotificationAsync(toast);
}
5.在控制台程序的Main函数中添加
SendNotificationAsync();
Console.ReadLine();
6.运行控制台程序,然后所有安装了刚才创建的Windows商店应用的电脑都会弹出如下推送消息
分享到:
相关推荐
Queue存储服务与应用程序问通信、云上的关系数据库:SQL Azure、云上的访问控制技术:AppFabric Access Control、云服务的集散中心:AppFabric Service Bus、Windows Azure与其他平台的互操作性、云计算与Windows ...
《实战windows azure:微软云计算平台技术详解》来自于微软 windows azure mvp 的技术实践和心得体会,主要包括windows azure 平台的基础知识、使用方法、功能特点以及如何基于windows azure 平台设计高可靠、可扩展...
《云计算(第二版)》教材配套课件[PPT] 第四章 微软云计算Windows Azure(2).ppt
QCon 2009 beijing全球企业开发大会ppt: ...6.微软云计算平台-Windows Azure架构探析 ...通过这一个主题,您将会了解微软云计算策略,Windows Azure平台包含的内容以及如何能帮助企业构建云端应用,如何开发等。
《实战Windows Azure:微软云计算平台技术详解》来自于微软 Windows Azure MVP 的技术实践和心得体会,主要包括Windows Azure 平台的基础知识、使用方法、功能特点以及如何基于Windows Azure 平台设计高可靠、可扩展...
实战 Windows Azure:微软云计算平台技术详解
QCon 2009 beijing全球企业开发大会ppt:(共25个资料,若要下载其他部分,点击 标签“QCon”...通过这一个主题,您将会了解微软云计算策略,Windows Azure平台包含的内容以及如何能帮助企业构建云端应用,如何开发等。
实战WindowsAzure:微软云计算平台技术详解(目录)实战WindowsAzure:微软云计算平台技术详解(目录)
《云计算(第二版)》教材配套课件[PPT] 第四章 微软云计算Windows Azure(1).ppt
《实战windows azure 微软云计算平台技术详解》。
第4章 微软云计算第三版Windows Azure(一) 第4章 微软云计算第三版Windows Azure(二) 第4章 微软云计算第三版Windows Azure(三) 第4章 微软云计算第三版Windows Azure(四) 第5章 Hadoop 2.0 主流开源云架构(一) 第...
第4章 微软云计 算第三版Windows Azure(一) 第4章 微软云计算第三版Windows Azure(二) 第4章 微软云计算第三版Windows Azure(三) 第4章 微软云计算第三版Windows Azure(四) 第5章 Hadoop 2.0 主流开源云架构(一) ...
第4章 微软云计算第三版Windows Azure(一) 第4章 微软云计算第三版Windows Azure(二) 第4章 微软云计算第三版Windows Azure(三) 第4章 微软云计算第三版Windows Azure(四) 第5章 Hadoop 2.0 主流开源云架构(一) 第...
微软Windows Azure云计算平台
第4章 微软云计算第三版Windows Azure(一) 第4章 微软云计算第三版Windows Azure(二) 第4章 微软云计算第三版Windows Azure(三) 第4章 微软云计算第三版Windows Azure(四) 第5章 Hadoop 2.0 主流开源云架构(一) 第...
微软的云计算平台AZURE
本书特别为云计算的入门读者编写,对于云计算技术人员、技术战略分析人员和爱好者也有重要的参考价值,还可供高等院校云计算和并行计算的研究者和同学作为参考资料及教材使用。
深入浅出介绍微软Windows Azure云计算平台
Windows Azure 表存储:不同于传统数据库.pdf