A Hitchhiker's Guide 
to 
Azure Mobile Services
@DavidGiard 
David Giard 
Microso. 
Technical 
Evangelist 
• @DavidGiard 
• DavidGiard.com 
• TechnologyAndFriends 
• dGiard@microso..com
@DavidGiard 
Agenda 
• Why 
Azure 
Mobile 
Services? 
• Mobile 
Architecture 
• Common 
Data 
Access 
• CustomizaCon 
• Dynamic 
Data 
• Client 
Code 
• IdenCty 
and 
Permissions 
• Scaling 
• API 
Scripts 
• NoCficaCons
@DavidGiard 
Why Azure Mobile Services? 
• Frees 
you 
from 
plumbing 
code 
• Handles 
API 
Changes 
• Cross-­‐PlaLorm 
soluCon 
• Choose 
JavaScript 
or 
.NET
@DavidGiard 
Mobile Architecture 
Windows 
Phone 
Data 
Windows 
8.1 
iPhone 
iPad 
Android 
REST 
API 
JavaScript
@DavidGiard 
Pieces of Azure Mobile Services 
Permissions 
SQL 
Server 
table 
READ 
INSERT 
UPDATE 
DELETE 
Client 
Code 
IdenCty
@DavidGiard 
CreaBng a Mobile Service
@DavidGiard 
CreaBng a Mobile Service
@DavidGiard 
CreaBng a Mobile Service
@DavidGiard 
REST 
hUps://Giard.azure-­‐mobile.net/Tables/Table1 
• GET, 
PUT, 
POST, 
DELETE, 
PATCH 
• Extend 
GET 
with 
oData 
Query 
syntax
@DavidGiard 
REST 
Client 
Endpoint 
Request 
Verb 
Data 
(JSON) 
Response
@DavidGiard 
REST 
HTTP 
Verb 
Ac+on 
SQL 
GET 
Read 
Data 
SELECT… 
POST 
Create 
Data 
INSERT… 
DELETE 
Delete 
Data 
DELETE… 
PUT 
or 
PATCH 
Update 
Data 
UPDATE…
@DavidGiard 
oData Query Syntax 
Extension 
Descrip+on 
$filter 
WHERE 
clause 
$inlinecount 
# 
items 
in 
table 
$orderby 
SORT 
clause 
$select 
Columns 
to 
return 
$skip 
#records 
to 
skip 
$top 
#records 
to 
return 
../Tables/Table1?$filter=AcCve 
eq 
true 
../Tables/Table1?$filter=AcCve%20eq%20true 
../Tables/Table1$filter=AcCve%20eq%20true&$orderby=LastName
@DavidGiard 
Dynamic Schema 
• “Configure” 
tab 
• AutomaCcally 
adds 
columns 
if 
matching 
data 
submiUed 
• Useful 
during 
development 
• Turn 
off 
during 
producCon
@DavidGiard 
Permissions
@DavidGiard 
Scripts 
• Insert 
• Update 
• Delete 
• Read
@DavidGiard 
Demo
@DavidGiard 
IdenBty – Single Sign-­‐On 
Client 
TwiUer 
or 
Facebook 
or 
Google 
or 
Microso. 
Azure 
Mobile 
Services 
API 
Request 
TOKEN
@DavidGiard 
IdenBty
@DavidGiard 
IdenBty 
funcCon 
insert(item, 
user, 
request) 
{ 
item.CreatedBy 
= 
user.userId; 
request.execute(); 
} 
funcCon 
read(query, 
user, 
request) 
{ 
query.where 
({CreatedBy:user.userId}); 
request.execute(); 
}
@DavidGiard 
Demo
@DavidGiard 
Scaling
@DavidGiard 
Scaling
@DavidGiard 
API Scripts
@DavidGiard 
API Scripts 
<Mobile 
Service 
URL>/api/<API 
Name> 
hUps://giard.azure-­‐mobile.net/api/MyApi 
exports.post 
= 
funcCon(request, 
response) 
{ 
// 
Use 
"request.service" 
to 
access 
features 
of 
your 
mobile 
service, 
e.g.: 
// 
var 
tables 
= 
request.service.tables; 
// 
var 
push 
= 
request.service.push; 
response.send(statusCodes.OK, 
{ 
message 
: 
'Hello 
World!' 
}); 
}; 
exports.get 
= 
funcCon(request, 
response) 
{ 
response.send(statusCodes.OK, 
{ 
message 
: 
'Hello 
World!' 
}); 
};
@DavidGiard 
Scheduler
@DavidGiard 
Mobile Services in .NET
@DavidGiard 
Mobile Services in .NET
@DavidGiard 
Demo
@DavidGiard 
Push NoBficaBons
@DavidGiard 
Push NoBficaBons 
var 
payload 
= 
App 
Push 
Service 
APN 
(Apple) 
GCM 
(Google) 
WNS 
(Windows 
8) 
MPNS 
(Windows 
Phone) 
Azure 
Mobile 
Services 
'<?xml 
version="1.0" 
encoding="uL-­‐8"?><toast><visual><binding 
template="ToastText01">' 
+ 
'<text 
id="1">Sample 
Toast</text></binding></visual></toast>'; 
var 
push 
= 
request.service.push; 
push.wns.send(null, 
payload, 
'wns/toast', 
{ 
success: 
funcCon 
(pushResponse) 
{ 
console.log("Sent 
push:", 
pushResponse); 
} 
}); 
}
@DavidGiard 
exports.post 
= 
funcCon(request, 
response) 
{ 
response.send(statusCodes.OK,{ 
message 
: 
'Hello 
World!' 
}) 
// 
The 
following 
call 
is 
for 
illustraCon 
purpose 
only 
// 
The 
call 
and 
funcCon 
body 
should 
be 
moved 
to 
a 
script 
in 
your 
app 
// 
where 
you 
want 
to 
send 
a 
noCficaCon 
sendNoCficaCons(request); 
}; 
// 
The 
following 
code 
should 
be 
moved 
to 
appropriate 
script 
in 
your 
app 
where 
noCficaCon 
is 
sent 
funcCon 
sendNoCficaCons(request) 
{ 
var 
payload 
= 
'<?xml 
version="1.0" 
encoding="uL-­‐8"?><toast><visual><binding 
template="ToastText01">' 
+ 
'<text 
id="1">Sample 
Toast</text></binding></visual></toast>'; 
var 
push 
= 
request.service.push; 
push.wns.send(null, 
payload, 
'wns/toast', 
{ 
success: 
funcCon 
(pushResponse) 
{ 
console.log("Sent 
push:", 
pushResponse); 
} 
}); 
}
@DavidGiard 
Push NoBficaBons 
Azure 
Mobile 
Services 
Push 
Service 
APN 
(Apple) 
GCM 
(Google) 
WNS 
(Windows 
8) 
MPNS 
(Windows 
Phone) 
NoCficaCon 
Hub
@DavidGiard 
So Long and Thanks! 
David 
Giard 
• @DavidGiard 
• DavidGiard.com 
• TechnologyAndFriends.com

The Hitchhicker’s Guide to Windows Azure Mobile Services | FalafelCON 2014

  • 1.
    A Hitchhiker's Guide to Azure Mobile Services
  • 2.
    @DavidGiard David Giard Microso. Technical Evangelist • @DavidGiard • DavidGiard.com • TechnologyAndFriends • dGiard@microso..com
  • 3.
    @DavidGiard Agenda •Why Azure Mobile Services? • Mobile Architecture • Common Data Access • CustomizaCon • Dynamic Data • Client Code • IdenCty and Permissions • Scaling • API Scripts • NoCficaCons
  • 4.
    @DavidGiard Why AzureMobile Services? • Frees you from plumbing code • Handles API Changes • Cross-­‐PlaLorm soluCon • Choose JavaScript or .NET
  • 5.
    @DavidGiard Mobile Architecture Windows Phone Data Windows 8.1 iPhone iPad Android REST API JavaScript
  • 6.
    @DavidGiard Pieces ofAzure Mobile Services Permissions SQL Server table READ INSERT UPDATE DELETE Client Code IdenCty
  • 7.
    @DavidGiard CreaBng aMobile Service
  • 8.
    @DavidGiard CreaBng aMobile Service
  • 9.
    @DavidGiard CreaBng aMobile Service
  • 10.
    @DavidGiard REST hUps://Giard.azure-­‐mobile.net/Tables/Table1 • GET, PUT, POST, DELETE, PATCH • Extend GET with oData Query syntax
  • 11.
    @DavidGiard REST Client Endpoint Request Verb Data (JSON) Response
  • 12.
    @DavidGiard REST HTTP Verb Ac+on SQL GET Read Data SELECT… POST Create Data INSERT… DELETE Delete Data DELETE… PUT or PATCH Update Data UPDATE…
  • 13.
    @DavidGiard oData QuerySyntax Extension Descrip+on $filter WHERE clause $inlinecount # items in table $orderby SORT clause $select Columns to return $skip #records to skip $top #records to return ../Tables/Table1?$filter=AcCve eq true ../Tables/Table1?$filter=AcCve%20eq%20true ../Tables/Table1$filter=AcCve%20eq%20true&$orderby=LastName
  • 14.
    @DavidGiard Dynamic Schema • “Configure” tab • AutomaCcally adds columns if matching data submiUed • Useful during development • Turn off during producCon
  • 15.
  • 16.
    @DavidGiard Scripts •Insert • Update • Delete • Read
  • 17.
  • 18.
    @DavidGiard IdenBty –Single Sign-­‐On Client TwiUer or Facebook or Google or Microso. Azure Mobile Services API Request TOKEN
  • 19.
  • 20.
    @DavidGiard IdenBty funcCon insert(item, user, request) { item.CreatedBy = user.userId; request.execute(); } funcCon read(query, user, request) { query.where ({CreatedBy:user.userId}); request.execute(); }
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
    @DavidGiard API Scripts <Mobile Service URL>/api/<API Name> hUps://giard.azure-­‐mobile.net/api/MyApi exports.post = funcCon(request, response) { // Use "request.service" to access features of your mobile service, e.g.: // var tables = request.service.tables; // var push = request.service.push; response.send(statusCodes.OK, { message : 'Hello World!' }); }; exports.get = funcCon(request, response) { response.send(statusCodes.OK, { message : 'Hello World!' }); };
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
    @DavidGiard Push NoBficaBons var payload = App Push Service APN (Apple) GCM (Google) WNS (Windows 8) MPNS (Windows Phone) Azure Mobile Services '<?xml version="1.0" encoding="uL-­‐8"?><toast><visual><binding template="ToastText01">' + '<text id="1">Sample Toast</text></binding></visual></toast>'; var push = request.service.push; push.wns.send(null, payload, 'wns/toast', { success: funcCon (pushResponse) { console.log("Sent push:", pushResponse); } }); }
  • 32.
    @DavidGiard exports.post = funcCon(request, response) { response.send(statusCodes.OK,{ message : 'Hello World!' }) // The following call is for illustraCon purpose only // The call and funcCon body should be moved to a script in your app // where you want to send a noCficaCon sendNoCficaCons(request); }; // The following code should be moved to appropriate script in your app where noCficaCon is sent funcCon sendNoCficaCons(request) { var payload = '<?xml version="1.0" encoding="uL-­‐8"?><toast><visual><binding template="ToastText01">' + '<text id="1">Sample Toast</text></binding></visual></toast>'; var push = request.service.push; push.wns.send(null, payload, 'wns/toast', { success: funcCon (pushResponse) { console.log("Sent push:", pushResponse); } }); }
  • 33.
    @DavidGiard Push NoBficaBons Azure Mobile Services Push Service APN (Apple) GCM (Google) WNS (Windows 8) MPNS (Windows Phone) NoCficaCon Hub
  • 34.
    @DavidGiard So Longand Thanks! David Giard • @DavidGiard • DavidGiard.com • TechnologyAndFriends.com