Windows Azure Mobile Services
-
Upload
sasha-goldshtein -
Category
Technology
-
view
549 -
download
1
description
Transcript of Windows Azure Mobile Services
© Copyright SELA software & Education Labs Ltd. | 14-18 Baruch Hirsch St Bnei Brak, 51202 Israel | www.selagroup.com
Sasha Goldshtein @goldshtnCTO, SELA Group blog.sashag.netWindows Azure Mobile Services
Who Are We? App DevelopersWhat 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 PhoneiOS & AndroidHTML & JavaScriptData & LINQ queriesServer scripts, schedulerAuthentication & WAADNEW
Custom APINEW
Source control and NPMNEW
Push, notification hubsNEW
Demo
Windows Azure Mobile Services Portal
Initializing The Mobile Service Client
Windows 8 / Windows Phone / AndroidiOS
ms = new MobileServiceClient("https://rentahome.azure-mobile.net","..." /*API key*/);
ms = [MSClient clientWithApplicationURLString:"https://rentahome.azure-mobile.net"
applicationKey:"..."];
The application key is for development purposes only. In production, use user authentication to limit access to data
Accessing Data
// Windows 8 and Windows Phonevar apartments = await ms.GetTable<Apartment>() .Where(a => a.Bedrooms > 2).ToListAsync();
// Androidms.getTable(Apartment.class).where(). .field("bedrooms").gt(2).execute(...);
// iOSNSPredicate *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.jsCan 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 serviceVery 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); } });};
Demo
Enriching Data with Server Scripts
Push
On trigger, send push from scriptUnfortunately, push API differs for each platform
Prepare app for push notificationsDepends on platform
push.wns.sendToast02(channel.uri, { text01: "New apartment added", text02: apartment.address });
Channel = await PushNotificationChannelManager. CreatePushNotificationChannelForApplicationAsync();channelsTable.Insert(new Channel(Channel.Uri));
Notification Hubs
Blast out push messages based on the template and the tagsRegister templates for push notifications with arbitrary custom tags
var payload = { message : message };hub.send(tag, payload, function(error, outcome) { ... });
template = { data: { message: '$(message)' } };hub.gcm.createTemplateRegistration(request.body.uri, tags, template, registrationComplete);
Demo
Server-Side Push Support
Authentication
// iOSif (!client.currentUser) { [self presentViewController:[client loginViewControllerWithProvider:@"twitter" completion:(MSUser *user, NSError *err) ... ] animated:YES];}
// Androidif (client.getCurrentUser() != null) { client.login( MobileServiceAuthenticationProvider.Twitter, new UserAuthenticationCallback() ...);}
Demo
Authentication
Summary
Windows Azure Mobile Services provide a powerful and customizable backend for your mobile appsCode available at http://github.com/goldshtn/rentahome
QuestionsSasha Goldshtein @goldshtnCTO, SELA Group blog.sashag.net