Sasha Goldshtein
CTO, SELA Group

@goldshtn
blog.sashag.net

Windows Azure Mobile
Services

© Copyright SELA software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com
Who Are We? App Developers
What Do We Hate? Backends
We need one backend for all our
mobile apps, scaled by the cloud
Oh, and it should cost about $0-5 /
month for a small, simple app
Backend as a Service
Windows 8 & Windows Phone
iOS & Android
HTML & JavaScript
Data & LINQ queries
Server scripts, scheduler
Authentication & WAADNEW
Custom APINEW
Source control and NPMNEW
Push, notification hubsNEW
Windows Azure Mobile Services
Portal

Demo
Initializing The Mobile Service
Client
The application key is for development
iOS
Windows 8 / Windows PhoneIn Android use user
purposes only. / production,
authentication to limit access to data
ms = new MobileServiceClient(
[MSClient clientWithApplicationURLString:
"https://rentahome.azure-mobile.net"
"https://rentahome.azure-mobile.net",
"..." /*API key*/);
applicationKey:"..."];
Accessing Data
// Windows 8 and Windows Phone
var apartments = await ms.GetTable<Apartment>()
.Where(a => a.Bedrooms > 2).ToListAsync();
// Android
ms.getTable(Apartment.class).where().
.field("bedrooms").gt(2).execute(...);
// iOS
NSPredicate *pred = [NSPredicate
predicateWithFormat:@"bedrooms > 2"];
[[client getTable:@"apartment"] readWhere:pred
completion:^...];
Server Scripts
CRUD operations can pass through a custom
script
Use for validation, data enrichment, etc.
Scripts are written in JavaScript and run on Node.js
Can access several Node modules:
request, push, …
function insert(item, user, request) {
if (item.address.length === 0) {
request.respond(400);
} else {
request.execute();
}
}
Custom API
Add custom HTTP endpoints to your mobile
service
Very useful for external access
exports.post = function(request, response) {
sharedHub.send_ad(request.body.message, function(error) {
if (error) {
response.send(500, 'Error sending ad: ' + error);
} else {
response.send(200);
}
});
};
Enriching Data with Server Scripts

Demo
Push
Prepare app for push from script
On trigger, send push notifications
Depends on platform
Unfortunately, push API differs for each platform
Channel = await PushNotificationChannelManager.
push.wns.sendToast02(channel.uri, {
text01: "New apartment added",
CreatePushNotificationChannelForApplicationAsync();
channelsTable.Insert(new Channel(Channel.Uri));
text02: apartment.address });
Notification Hubs
Register push messages based on the
Blast out templates for push notifications with
arbitrary and the tags
template custom tags
template =
var payload{=data: { message: '$(message)' } };
{ message : message };
hub.gcm.createTemplateRegistration(request.body.uri, });
hub.send(tag, payload, function(error, outcome) { ...tags,
template, registrationComplete);
Server-Side Push Support

Demo
Authentication
// iOS
if (!client.currentUser) {
[self presentViewController:[client
loginViewControllerWithProvider:@"twitter"
completion:(MSUser *user, NSError *err) ...
] animated:YES];
}
// Android
if (client.getCurrentUser() != null) {
client.login(
MobileServiceAuthenticationProvider.Twitter,
new UserAuthenticationCallback() ...);
}
Authentication

Demo
Summary
Windows Azure Mobile Services provide a
powerful and customizable backend for your
mobile apps
Code available at
http://github.com/goldshtn/rentahome
Questions
Sasha Goldshtein
CTO, SELA Group

@goldshtn
blog.sashag.net

Windows Azure Mobile Services

  • 1.
    Sasha Goldshtein CTO, SELAGroup @goldshtn blog.sashag.net Windows Azure Mobile Services © Copyright SELA software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com
  • 2.
    Who Are We?App Developers What Do We Hate? Backends
  • 3.
    We need onebackend for all our mobile apps, scaled by the cloud Oh, and it should cost about $0-5 / month for a small, simple app
  • 4.
    Backend as aService Windows 8 & Windows Phone iOS & Android HTML & JavaScript Data & LINQ queries Server scripts, scheduler Authentication & WAADNEW Custom APINEW Source control and NPMNEW Push, notification hubsNEW
  • 5.
    Windows Azure MobileServices Portal Demo
  • 6.
    Initializing The MobileService Client The application key is for development iOS Windows 8 / Windows PhoneIn Android use user purposes only. / production, authentication to limit access to data ms = new MobileServiceClient( [MSClient clientWithApplicationURLString: "https://rentahome.azure-mobile.net" "https://rentahome.azure-mobile.net", "..." /*API key*/); applicationKey:"..."];
  • 7.
    Accessing Data // Windows8 and Windows Phone var apartments = await ms.GetTable<Apartment>() .Where(a => a.Bedrooms > 2).ToListAsync(); // Android ms.getTable(Apartment.class).where(). .field("bedrooms").gt(2).execute(...); // iOS NSPredicate *pred = [NSPredicate predicateWithFormat:@"bedrooms > 2"]; [[client getTable:@"apartment"] readWhere:pred completion:^...];
  • 8.
    Server Scripts CRUD operationscan pass through a custom script Use for validation, data enrichment, etc. Scripts are written in JavaScript and run on Node.js Can access several Node modules: request, push, … function insert(item, user, request) { if (item.address.length === 0) { request.respond(400); } else { request.execute(); } }
  • 9.
    Custom API Add customHTTP endpoints to your mobile service Very useful for external access exports.post = function(request, response) { sharedHub.send_ad(request.body.message, function(error) { if (error) { response.send(500, 'Error sending ad: ' + error); } else { response.send(200); } }); };
  • 10.
    Enriching Data withServer Scripts Demo
  • 11.
    Push Prepare app forpush from script On trigger, send push notifications Depends on platform Unfortunately, push API differs for each platform Channel = await PushNotificationChannelManager. push.wns.sendToast02(channel.uri, { text01: "New apartment added", CreatePushNotificationChannelForApplicationAsync(); channelsTable.Insert(new Channel(Channel.Uri)); text02: apartment.address });
  • 12.
    Notification Hubs Register pushmessages based on the Blast out templates for push notifications with arbitrary and the tags template custom tags template = var payload{=data: { message: '$(message)' } }; { message : message }; hub.gcm.createTemplateRegistration(request.body.uri, }); hub.send(tag, payload, function(error, outcome) { ...tags, template, registrationComplete);
  • 13.
  • 14.
    Authentication // iOS if (!client.currentUser){ [self presentViewController:[client loginViewControllerWithProvider:@"twitter" completion:(MSUser *user, NSError *err) ... ] animated:YES]; } // Android if (client.getCurrentUser() != null) { client.login( MobileServiceAuthenticationProvider.Twitter, new UserAuthenticationCallback() ...); }
  • 15.
  • 16.
    Summary Windows Azure MobileServices provide a powerful and customizable backend for your mobile apps Code available at http://github.com/goldshtn/rentahome
  • 17.
    Questions Sasha Goldshtein CTO, SELAGroup @goldshtn blog.sashag.net

Editor's Notes

  • #6 Open the portal, show the general service settings and the dashboard that kind of gives you an app skeleton for free.Then, show the data tab with the tables we have, and basic data manipulation on these tables.Mention the concept of server scripts on CRUD operations – but don’t show these scripts yet.
  • #11 Show the insert script on the apartments table.Explain that we’re using geocoding to obtain coordinates for the apartment, and we’re also pulling some information from Twitter (the user’s display name) – this will be explained later when we discuss authentication.
  • #14 Show the channels table that contains the channels and the device types – this is necessary because the push semantics are different for each platform.Show the insert script on the apartments table again, and explain that it uses four different methods of the push module to deliver the push to the appropriate platform.
  • #16 Demo the full app experience on all four platforms: login, add a new apartment, show push on other devices, delete an apartment, view maps (based on coordinates provided by the server).