当前位置: 首页 > news >正文

深圳装饰网站建设/近期10大新闻事件

深圳装饰网站建设,近期10大新闻事件,太原零元网站建设,网站建设基础百度百科前言 随着Windows Azure 在中国的正式落地,相信越来越多的人会体验到Windows Azure带来的强大和便利。在上一篇文章中, 我们介绍了如何利用Windows Azure中的Service Bus的中继功能(Relay),来将您的WCF服务册到Windows Azure Service Bus上。…

前言

随着Windows Azure 在中国的正式落地,相信越来越多的人会体验到Windows Azure带来的强大和便利。在上一篇文章中, 我们介绍了如何利用Windows Azure中的Service Bus的中继功能(Relay),来将您的WCF服务册到Windows Azure Service Bus上。 而WCF客户端可以通过访问Service Bus endpoint, 从而访问到您真正的WCF服务。
在这篇文章中,我们将介绍Windows Azure Service Bus的另外一个功能:通知中心(Notification Hub)。 (说明: 该功能目前还处于Preview阶段)
在很多应用系统中,通过Publisher |Subscriber 模型 来实现消息推送是一个常用的功能。实现方法也有很多,且较为复杂。幸运的是,在Windows Azure Service Bus中, 我们提供一个功能:通知中心(Notification Hub), 可以非常方便地实现大批量的推送通知的功能。
下面, 我就以开发一个简单的Windows 8 application为例,介绍如何利用这个功能实现Toast notification。

前提条件

1. 开发环境:Visual Studio 2012 + Windows 8
2. Windows Azure 账号 (您可以通过以下地址免费申请一个: http://www.azure.com)
3. Windows 8开发者账号。
4. Service Bus WinRT Preview SDK (http://go.microsoft.com/fwlink/?LinkID=277160)

正文

第一部分:配置

1. 首先, 您可以创建一个用于演示的Windows Store application。为了接收推送下来的Toast Notification,您必须先要开启该功能, 如下所示:

2. 然后,将该application和Windows Store关联起来,并在Windows Store里面正确配置该application, 比如Notification等等,并获取正确的Package Security Identifier (SID) 和Client secret。

里面最关键的一步,是要配置你的application的推送通知的功能,并获得相应的Package Security Identifier (SID) 和Client secret。
比如:下面就是我配置后生成的相应SID和Client secret:

3. 接下来, 我们需要回到Windows Azure  Management Portal, 创建一个Notification Hub。 比如,我在namesapce4push下,创建了一个叫做myhub的 Notification Hub,如下所示:

4. 然后,给刚才创建的Notification Hub : myhub 指定相应的Package SID和Client Secret,使得我们自己开发的application和该notification hub关联起来,如下所示:

最后点击保存。

5. 上述设置结束之后,回到Visual Studio,其会自动检测到这一行为,点击下一步直至结束,这样该application和store成功关联起来了。

第二部分:编写代码

1. 在application里面,我们需要在程序启动的时候,完成一些初始化的动作,比如该application在Notification Hub的注册等。
下面用黄色高亮显示的部分为相关代码:

using PushDemo.Common;using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Threading.Tasks;using Microsoft.WindowsAzure.Messaging;
using Windows.Networking.PushNotifications;
using Windows.UI.Notifications;
using Windows.Data.Xml.Dom;// The Grid App template is documented at http://go.microsoft.com/fwlink/?LinkId=234226namespace PushDemo
{/// <summary>/// Provides application-specific behavior to supplement the default Application class./// </summary>sealed partial class App : Application{/// <summary>/// Initializes the singleton Application object.  This is the first line of authored code/// executed, and as such is the logical equivalent of main() or WinMain()./// </summary>/// 
NotificationHub notificationHub;public App(){var cn = ConnectionString.CreateUsingSharedAccessSecretWithListenAccess(new Uri("sb://namespace4push.servicebus.windows.net/"),"******<listenAccessSecret>******");notificationHub = new NotificationHub("myhub", cn);this.InitializeComponent();this.Suspending += OnSuspending;}async Task InitializeNotificationsAsync(){var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();await notificationHub.RefreshChannelUriAsync(channel.Uri);if (!await notificationHub.TemplateRegistrationExistsAsync("myToastRegistration"))await notificationHub.CreateTemplateRegistrationAsync(BuildTextToastTemplate(), "myToastRegistration");}XmlDocument BuildTextToastTemplate(){var template =ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);var textNode = template.SelectSingleNode("//text[@id='1']") as XmlElement;if (textNode != null){textNode.InnerText = "$(msg)";}return template;}/// <summary>/// Invoked when the application is launched normally by the end user.  Other entry points/// will be used when the application is launched to open a specific file, to display/// search results, and so forth./// </summary>/// <param name="args">Details about the launch request and process.</param>protected override async void OnLaunched(LaunchActivatedEventArgs args){await InitializeNotificationsAsync();Frame rootFrame = Window.Current.Content as Frame;// Do not repeat app initialization when the Window already has content,// just ensure that the window is activeif (rootFrame == null){// Create a Frame to act as the navigation context and navigate to the first page
…
…}// Ensure the current window is active
            Window.Current.Activate();}/// <summary>/// Invoked when application execution is being suspended.  Application state is saved/// without knowing whether the application will be terminated or resumed with the contents/// of memory still intact./// </summary>/// <param name="sender">The source of the suspend request.</param>/// <param name="e">Details about the suspend request.</param>
…
…}
}

 

2. 接下来我们需要一个用来推送消息的后台程序。我们就用一个非常简单的windows console程序来模拟后台好了。相关的代码如下:

class Program{static void Main(string[] args){var cn = ServiceBusConnectionStringBuilder.CreateUsingSharedAccessKey(new Uri("sb://namespace4push.servicebus.windows.net/"),Microsoft.ServiceBus.Notifications.NotificationHubDescription.DefaultFullSasRuleName,"*****<Access key>********”
                );var hbClient = Microsoft.ServiceBus.Notifications.NotificationHubClient.CreateClientFromConnectionString(cn, "myhub");hbClient.SendTemplateNotification(new Dictionary<string, string>{{"msg",args.Length>0? args[0]:"Hello World, Service Bus Notification Hub"}});}}

3. 运行后的效果如下:
1)首先, 我们用我们的模拟后台消息推送程序推送一条消息给Notification Hub,如下:

2)因为我们的Windows Store Application注册到了Service Bus Notification Hub。 因此,所有安装该application的终端都会马上收到一个Toast Notification,如下:

也就是说, 假设我们有1万个终端的话, 那么这一万个终端会同时收到该Toast Notification.
说明:在Notification Hub Preview阶段,目前一个Notification Hub最多支持10,000个注册。如果需要超过1万个的注册,需要和我们的产品组联系以便特殊处理。

参考文档:

1) How To: Service Bus Notification Hubs (Windows Store Apps)
http://msdn.microsoft.com/en-us/library/windowsazure/jj927172.aspx
2) Creating Windows Store Apps with Windows Azure Notification Hubs
http://blogs.msdn.com/b/zxue/archive/2013/01/24/creating-windows-store-apps-with-windows-azure-notification-hubs.aspx

 

希望以上内容对您有所帮助

 

Winston He

 

  

转载于:https://www.cnblogs.com/developersupport/p/Azure-Service-Bus-Notification-Hub.html

http://www.lbrq.cn/news/1378495.html

相关文章:

  • 湛江市网站建设/新品推广活动方案
  • 沈阳紧急通知/优化绿松石什么意思
  • 网站建设及维护机/足球队世界排名榜
  • 哈尔滨快速建站服务热线/2345浏览器下载安装
  • 企业网站建设合同书标准版/教育培训机构有哪些
  • 做网站的网络公司有哪些/建立网站需要多少钱
  • wordpress前端上传头像/seo门户网站
  • 怎么做网站建设/seo零基础教学
  • 怎么用dw做动态网站/南京网站制作
  • 上海创新网站建设/站长统计代码
  • 主机如何做网站空间/重庆网络推广外包
  • 莆田制作网站企业/手机如何制作网站
  • 日照建站/网络推广大概需要多少钱
  • 成都神速建站/免费正规大数据查询平台
  • 海盗湾的Wordpress安装/搜索引擎优化培训免费咨询
  • 埃及网站后缀/整合营销的特点有哪些
  • 大连外贸网站建设/百度优化大师
  • 高端网站设计思路/seo专业培训机构
  • 做网站怎么查看来访ip/嘉兴网站建设
  • 厦门网站建设2015/百度优化培训
  • 在网站底部给网站地图做链接/东莞网站seo推广
  • 推广网站怎么做模版/首页优化排名
  • 做酒店的网站/北京网讯百度科技有限公司
  • 桂林小学网站建设/西安seo外包公司
  • wordpress中文url/重庆seo网站系统
  • 如何做平台网站/今天今日头条新闻
  • 网站建设制作设计seo优化珠海/百度搜索官方网站
  • 多语言网站建设/广告seo是什么意思
  • 东莞网站建设哪家专业/软文推广文案
  • 软件开发网站能做seo吗/郑州百度推广开户
  • Python day31
  • 探索 VMware 虚拟机:开启虚拟化世界的大门
  • Linux选择
  • SpringBoot+Mybatis+MySQL+Vue+ElementUI前后端分离版:日志管理(四)集成Spring Security
  • 数论:卢卡斯定理
  • O2OA 平台:助力企业在信创浪潮下实现高效国产化转型