4. Agenda
ā¢ Features
ā¢ Pricing
ā¢ Account setup
ā¢ Account configuration for storing data
ā¢ What kind of data can be added
ā¢ Custom scripts
ā¢ Authentication
ā¢ Available API
ā¢ Demo
5. Features of Mobile Services
ā¢ 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
6. 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
7. 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
8. Setup your account
ā¢ 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
9. Configure environment to store data
ā¢ 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
10. What kind of data can be added?
ā¢ 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
11. Custom scripts
ā¢ 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: JavaScript
function 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
12. 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 data
function insert(item, user, request) {
var request = require('request');
request('http://myFoo.com/Services/validate', function(err, response, body) {
...
});
}
13. Custom scripts
Catch the exception on the client
try
{
await myTable.InsertAsync(item);
items.Add(item);
}
catch (MobileServiceInvalidOperationException e)
{
Trace.Write("Error: " + e.Reponse.Content);
}
14. Control user access to data
ā¢ 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
15. How to work with 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