Service Bus Notification Hubs are a brand new intrinsic feature of Windows Azure Service Bus and are different from other push notification services in four key areas:
In this preview, Notification Hubs are able to push notifications to Windows Store apps and iOS apps from .NET back-ends. Support for Android and Windows Phone, along with additional back-end technologies (including Windows Azure Mobile Services) will be added soon.
After the basic intro, I'm showing how to create and provision a Windows 8 application from scratch, how to hook it up to a new Notification Hub, and send it a notification "Toast" using the portals and Visual Studio 2012. (The equivalent iOS walkthrough will follow later this week)
For those of you with a "TL;DW" attention span (too long; didn't watch), here's the whole extent of the code added to the stock Windows Store Grid template to enable Service Bus Notifications and that includes re-registering existing registrations at App startup. 5 lines without cosmetic wrapping and some massaging of XML for the template:
public App() { var cn = ConnectionString.CreateUsingSharedAccessSecretWithListenAccess( "sb://clemensv1.servicebus.windows.net", "{{secret-key}}"); this.notificationHub = new NotificationHub("myhub", cn);
... }
async Task InitNotificationsAsync() { await notificationHub.RefreshRegistrationsAsync(); if (!await notificationHub.RegistrationExistsForApplicationAsync("myToast")) { await notificationHub.CreateTemplateRegistrationForApplicationAsync( CreateTemplate(), "myToast"); } } XmlDocument CreateTemplate() { var t = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01); var n = t.SelectSingleNode("//text[@id='1']") as XmlElement; if (n != null) { n.InnerText = "$(msg)"; } return t; }
The event-source code is similarly terse:
var cn = ServiceBusConnectionStringBuilder.CreateUsingSharedAccessSecretWithFullAccess( "clemensv1", "{{{secret key}}"); var hubClient = NotificationHubClient. CreateClientFromConnectionString(cn, "myhub"); hubClient.SendTemplateNotification(new Dictionary<string, string>{ { "msg", TextBox1.Text }});
3 lines. Three lines. No management of device ids. No public endpoint for the phone to talk to. Service Bus does all that. It really is worth playing with.
And here are all the key links ....
SDKs: