微软云技术Windows Azure专题(一):如何利用Service Bus向Windows商店应用推送消息
3.将应用和商店连接起来
4.然后获取你的应用的惟一身份标识和客户端密钥
第二部:在Windows Azure中创建一个Service Bus,并在该Service Bus中创建一个通知中心
1.点击最下方的新建按钮
2.我们就建立一个名为BestAppRecommendation的名称空间
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 successfulif (result.RegistrationId != null){ var dialog = new MessageDialog("Registration successful: " + result.RegistrationId); dialog.Commands.Add(new UICommand("OK")); await dialog.ShowAsync();}}
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);}