Mobile services on windows azure (part2)
-
Upload
radu-vunvulea -
Category
Documents
-
view
572 -
download
0
Transcript of Mobile services on windows azure (part2)
{“name” : “Radu Vunvulea,“company” : “iQuest”,“userType” : “enthusiastic”“technologies” : [ “.NET”, “JS”, “Azure”, “Web”, “Mobile”, “SL” ],“w8experience” : [ “2 LoB App”, “1 Travel App”],“blog” : “vunvulearadu.blogspot.com”,“email” : ”[email protected]”,“socialMedia” :
{“twitter” : “@RaduVunvulea”,
“fb” : “radu.vunvulea”}
}
Who am I?
• This is the topic for today meeting
Windows Azure Mobile Services
• Features• Pricing• Account setup• Account configuration for storing data• What kind of data can be added• Custom scripts• Authentication• Available API• Demo
Agenda
• User authentication• Windows Live• Facebook• Google• Twitter
• Store data in the cloud• Windows Azure Storage
• Push notification infrastructure • All the service is build in in Windows Azure
Features of Mobile Services
• Free package in the 90 days trial:• Outbound traffic included 165MB• Maximum 10 mobile services
• Reserved instance model:• 3 dedicated servers (small instances, pay-as-you-go model)• 100 mobile services• Outbound data transfer will be paid
• Price available during preview can change in the final release
Pricing of Mobile Services
• Free package in the 90 days trial:• Outbound traffic included 165MB• Maximum 10 mobile services
• Reserved instance model:• 3 dedicated servers (small instances, pay-as-you-go model)• 100 mobile services• Outbound data transfer will be paid
• Price available during preview can change in the final release
Pricing of Mobile Services
• Create a new mobile service from the “New/Mobile Service/Create”
• A unique name of the mobile service need to be created• If we need a fresh database can be created or an existing
one can be used (if is in the same region)• After creating the database, we can use it as a normal database
• The service can be active for one of the following platform:• IOS• Windows Phone 8• Windows Store
• For each of the platform, after creating the mobile service, we can download the project that contains all the configurations
Setup your account
• From the management portal each service contains a tab named “Data”
• We can managed all the tables that we have • Create/Edit/Delete each table• See the content of each table
• For each table, we can set the rights of each user of the given table:• Anybody with the application key• Everyone• Only authenticate user• Only scripts and admin
• This rights can be different for CRUD operations
Configure environment to store data
• Any kind of serializable data• Each entity have to be decorated with DataContract and
DataMember attributes• It is recomanded to use the Name field of DataMember[DataContract]public class MyFoo{
public int Id { get;set;}
[DataMember(Name = "Name"]public string Name { get;set;}
}The “Id” field don’t need to be decorated with DataMember attribute
What kind of data can be added?
• Each CRUD operation can contain a custom script that is executed on the server side
• This scripts can be for validation purposes or to add/set custom fields
• Language: JavaScriptfunction insert(item, user, request) { if (item.name == "Tom") { request.respond(statusCodes.BAD_REQUEST, 'Tom name cannot be added'); } else { request.execute(); }}• When this kind of error appear, the client need to catch
“MobileServiceInvalidOperationException” exception
Custom scripts
• Each script can have helper functions• Base action that need to be done by a script
• execute – execute the given action• respond – send a response back to the client
• We cannot define global variable, each call is executed in a separate request
• Some of the base modules are from node.js• Example: we can make a request to another web-service to check datafunction insert(item, user, request) { var request = require('request'); request('http://myFoo.com/Services/validate', function(err, response, body) { ... }); }
Custom scripts
Catch the exception on the clienttry{ await myTable.InsertAsync(item); items.Add(item);}catch (MobileServiceInvalidOperationException e){
Trace.Write("Error: " + e.Reponse.Content);}
Custom scripts
• Define custom scripts that check if the given user id has rights to access his data
function insert(item, user, request) { item.userId = user.userId; request.execute();}function read(query, user, request) { query.where({ userId: user.userId }); request.execute();}• We need to store the user id. • Each user will have a unique user id• The user id is generated automatically by the system• We cannot store this scripts in our source control system
Control user access to data
• Define custom scripts that check if the given user id has rights to access his data
App.MobileService.GetTable<MyEntity>()• Before this we need to create a table with the same name• Update: table.UpdateAsync(entity)• Delete: table.DeleteAsync(entity)• Insert: table.InsertAsync(entity)• Fetch with data:
• Where• Take• Skip• OrderBy• Select• ThenBy• ToListAsync
How to work with data
Demo