2. What is Windows Azure Mobile
Services?
• A set of services build on Azure that provides backend ‘plumbing’ to
your mobile apps.
• Focus on building apps and not backend logic
– Data (dynamic schema)
– Authentication (Federated identities such as Facebook, Google,
Twitter, Windows Live)
– Server Logic (via Mobile Services Server Scripts)
– Push Notifications (GCM, APNS, WNS)
• Monitoring/Analytics/Logging infrastructure
• Client SDKs supported for Android, iOS, Windows Phone and
HTML/Javascript
3. Getting Started
• The service is not free
• ..but comes with a 3 month free trial (subject
to credit card verification)
• What you get:
http://www.windowsazure.com/en-
us/pricing/free-trial/
4. • DEMO: Azure Dashboard
• DEMO: Creating a new mobile service
• DEMO: Download the SDK and setup project
5. Mobile Service: Data
• Backend is Windows Azure SQL Database
• Dynamic schema – create your model in code,
and the fields are mapped by magic
• Throttling and failures are automatically
handled.
• NO RELATIONS (i.e. no foreign keys, cascade
logic etc)
7. Authentication
• Authenticate against: Facebook, Google,
Twitter, Windows Live
• Table level permissions for CRUD operations:
– Everyone (default)
– Only authenticated users
– Only scripts and admins
9. Server Scripts
• Similar to a trigger
• Allows you to build custom business logic when
something happens to your data
• Available operations: insert, update, read, delete (del)
e.g.:
function insert (id, user, request) {
request.execute();
}
10. Server Scripts: Continued
Insert: function insert(item, user, request) { }
Update: function update(item, user, request) { }
Delete: function del(id, user, request) { }
Read: function read(query, user, request) { }
•Script functions always take 3 arguments:
– 2nd
arg is always “user” (represents a user)
– 3rd
arg is always “request” (used to send responses).
– 1st
arg changes according to operation
11. Scripts: Continued
• Example:
function insert(item, user, request) {
if (item.userId !== user.userId) {
request.respond(statusCodes.FORBIDDEN, ‘Access Denied.');
} else {
request.execute();
}
}
* Complete script reference can be found at:
http://msdn.microsoft.com/en-us/library/windowsazure/jj554226.aspx
12. Push Notifications
• Allows direct push to devices
• Supported push services:
– GCM (API key required)
– APNS (Certificate required)
– WNS (Client secret & Package SID required)
N.B: For Windows Phone/WNS: 500 notifications/per user/per day.
14. Push Notifications: Step 1
Register App for Notifications
• GCM is the native push system for Android
• Register your app and enable GCM using
Google API console
(https://code.google.com/apis/console/)
15. Push Notifications: Step 2
Configure Mobile Services
• Copy generated API key from Google API
Services
• Select ‘Push’ from Azure Console and paste
key
17. Push Notifications: Step 4
Register your device & handle pushes
• Assuming you have ‘deviceId’ field on your data model:
String deviceId = GCMRegistrar.getRegistrationId(this);
Users.deviceId = deviceId;
//save here
• When a push arrives, onMessage fires:
protected void onMessage(Context context, Intent intent) {
//notify user etc.
}
http://developer.android.com/google/gcm/gs.html
18. Push Notifications: Step 5
Getting the server to notify
function insert(item, user, request) {
request.execute({ success: function() {
request.respond();
push.gcm.send(Users.deviceId, item.text);
}
}
19. Diagnostics, Logging and Scale
• Diagnostics:
– CPU Time
– Memory consumptions
– API calls/time taken per request
• Logging
– With server scripts via console.x (console.info,
console.error etc)
• Scale
– Scale up or down by spinning up new VMs or by
scaling up VM size
20. More Services
• Scheduler
– Schedule server scripts on demand or on interval
– Examples:
• Purge old data,
• Poll/aggregate data from other sources
• Schedule pushes to be sent at a certain time
• SendGrid (3rd
party service)
– Email-As-A-Service
• Pusher (3rd
party service)
– Enhanced push services (among other things)