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

34
A Hitchhiker's Guide to Azure Mobile Services

description

Windows Azure Mobile Services provides a straightforward way to connect your data to multiple applications on multiple devices. In this presentation, I will show how to expose cloud data via a REST interface and connect to that data from applications running on Windows Phone, Windows 8, iOs and Android. You will learn how to secure your data and to send push notification to your client application.

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

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

A  Hitchhiker's  Guide  to  

Azure  Mobile  Services

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

@DavidGiard  

David  Giard

Microso.  Technical  Evangelist  • @DavidGiard  • DavidGiard.com  •  TechnologyAndFriends  • [email protected]  

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

@DavidGiard  

Agenda

• Why  Azure  Mobile  Services?  • Mobile  Architecture  •  Common  Data  Access  •  CustomizaCon  •  Dynamic  Data  •  Client  Code  •  IdenCty  and  Permissions  •  Scaling  •  API  Scripts  •  NoCficaCons  

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

@DavidGiard  

Why  Azure  Mobile  Services?

•  Frees  you  from  plumbing  code  • Handles  API  Changes  • Cross-­‐PlaLorm  soluCon  • Choose  JavaScript  or  .NET  

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

@DavidGiard  

Mobile  Architecture

Windows  Phone  

Data  

Windows  8.1  

iPhone  

iPad  Android  

JavaScript  

REST  API  

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

@DavidGiard  

Permissions  

Pieces  of  Azure  Mobile  Services

SQL  Server  table  

READ  

INSERT  

UPDATE  

DELETE  

IdenCty  Client  Code  

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

@DavidGiard  

CreaBng  a  Mobile  Service

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

@DavidGiard  

CreaBng  a  Mobile  Service

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

@DavidGiard  

CreaBng  a  Mobile  Service

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

@DavidGiard  

REST

hUps://Giard.azure-­‐mobile.net/Tables/Table1  • GET,  PUT,  POST,  DELETE,  PATCH  •  Extend  GET  with  oData  Query  syntax  

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

@DavidGiard  

REST

Client  Endpoint  

Request  Verb  

Data  (JSON)  

Response  

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

@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…  

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

@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%20eq%20true  

../Tables/Table1?$filter=AcCve  eq  true  

../Tables/Table1$filter=AcCve%20eq%20true&$orderby=LastName  

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

@DavidGiard  

Dynamic  Schema

•  “Configure”  tab  • AutomaCcally  adds  columns  if  matching  data  submiUed  • Useful  during  development  •  Turn  off  during  producCon  

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

@DavidGiard  

Permissions

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

@DavidGiard  

Scripts

•  Insert  • Update  • Delete  • Read  

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

@DavidGiard  

Demo

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

@DavidGiard  

IdenBty  –  Single  Sign-­‐On

Client  

Azure  Mobile  Services  API  

TwiUer  or  Facebook    or  Google    

or  Microso.  

Request  

TOKEN  

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

@DavidGiard  

IdenBty

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

@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();  }  

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

@DavidGiard  

Demo

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

@DavidGiard  

Scaling

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

@DavidGiard  

Scaling

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

@DavidGiard  

API  Scripts

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

@DavidGiard  

API  Scripts

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!'  });  };  

<Mobile  Service  URL>/api/<API  Name>  

hUps://giard.azure-­‐mobile.net/api/MyApi  

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

@DavidGiard  

Scheduler

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

@DavidGiard  

Mobile  Services  in  .NET

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

@DavidGiard  

Mobile  Services  in  .NET

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

@DavidGiard  

Demo

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

@DavidGiard  

Push  NoBficaBons

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

@DavidGiard  

Push  NoBficaBons

App  

Push  Service  APN  (Apple)  GCM  (Google)  

WNS  (Windows  8)  MPNS  (Windows  Phone)  

Azure  Mobile  Services  

 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);                          }                  });  }  

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

@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);  

                       }  

               });  

}  

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

@DavidGiard  

Azure  Mobile  Services  

Push  NoBficaBons

Push  Service  APN  (Apple)  GCM  (Google)  

WNS  (Windows  8)  MPNS  (Windows  Phone)  

NoCficaCon  Hub  

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

@DavidGiard  

So  Long  and  Thanks!

David  Giard  • @DavidGiard  • DavidGiard.com  •  TechnologyAndFriends.com