Welcome to part nine of the blog series based on Vishwas Lele’s PluralSight course: Applied Azure. Previously, we’ve discussed Big Compute, Azure Web SitesAzure Worker RolesIdentity and Access with Azure Active DirectoryAzure Service Bus and MongoDBHIPPA Compliant Apps in Azure and Offloading SharePoint Customizations to Azure and “Big Data” with Windows Azure HDInsight.

Motivation

Windows Azure Mobile Services is a powerful building block in the Windows Azure platform. It brings together a set of services that enables you to create a versatile backend API very quickly. Moreover, it is supported by all major platforms such as Windows 8, Windows Phone, Android, iOS and HTML5.

Mobile Services provide a simple way to store data in the cloud and it also enables you to add custom endpoints to expose functionality other than database operations. Mobile service include out of the box authentication capability for all well-known Identity providers. It also provides scheduler functionality and auto-scale configuration options. The push notification is another powerful capability that can be used to send notifications to different devices.

Scenarios

There will be many scenarios where Mobile Services will fit in if you are building an application that is shared over multiple devices and platforms. You may like to create one data model and provide single interface that can be accessed from all platforms so that our code is highly reusable. Mobile Services is also helpful if you are building mobile application and you want to use well known Identity providers or if you need to send notifications to devices from your application.

Core Concept

Mobile Services support mobile application development on all major platforms. The following diagram depicts the core concept of the Azure Mobile Service. Applications may be shared on multiple platforms, which access the backend Mobile Service API using the platform specific client libraries.

Mobile_Services

Mobile Services provide different options to save the application data. You can use Windows Azure SQL database, blob storage, table storage or third party data services like Mongo DB. You can add business logic by injecting service scripts (C# or JavaScript) in the data access operations. Server scripts also known as scriptlets can execute Http requests. You can also do data validation, call azure table and blog storage, service bus or any third party API.

Mobile Services also supports custom API that enables us to add custom endpoints, which you can use to expose server functionality that is not related to any CRUD operation. Custom API allows you to have more control over messaging and provides the capability to use data formats other than JSON.

Job scheduler functionality of the mobile services can be used to execute the server script on-demand or based on the defined schedule. This can be used for maintenance tasks like archiving old data, updating master data from external data stores, etc.

Another powerful capability that Mobile Services provide is authentication. You can very easily integrate your application with providers like Facebook, Twitter, Microsoft and Google. For each provider, we can go to its developer site, add our application and copy over the generated application ID and secret. The application ID and secret generated by the provider can be configured in the Mobile Service directly in the Azure portal under the Identity tab. If you want to add custom authentication for your application you and also use the Azure Active Directory.

You can also use Mobile Services to send push notifications to different types of mobile devices using different provider services like Windows Notification Services, Apple Push Notification Services and Google Cloud Messaging. Mobile services can also be integrated with Notification Hub to send notifications to large number of devices or a group interested in specific type of notifications.

Mobile Services are based on Azure Websites and thus have the same SLA of 99.9% for the Standard tier. For scaling there are different manual options available but we can also use the use auto scale capability to increase or decrease resources based on the actual usage so that we can achieve the ideal performance and cost balance.

Design Considerations

Consider the data store that fits best for you application. It can be Azure SQL database, Azure Table Storage or any third party service.

In case of Azure SQL database you have the option to choose Dynamic Schema. Consider taking advantage of this in the early stages of you application. When applications evolve you may like to turn it off.

Use custom API when you need functionality other than CRUD operations and when you need more control over the messages like writing and reading message headers and using formats other than JSON.

Consider what type of authentication makes more sense for your application. Should you opt for any well-known provider or use Azure Active Directory. Apply authorization precisely for each table.

Azure Mobile Service is after all an REST API so the standard REST best practices should be considered.

Summary  

Azure Mobile Service is one of the main services available in Windows Azure Platform. We can use Mobile service as backend for any client application including mobile applications.

Mobile Service provides abstraction over data storage, which allows us to focus on application logic rather than worrying about underlying infrastructure. Custom API enables us to expose functionality with full control over messaging and data formatting. We can execute the maintenance code periodically based on a schedule or on-demand using the Mobile Service Scheduler capability. Applications can be authenticated using providers like Facebook, Twitter, Google, Microsoft or Azure Active Directory. We can send push notifications from Mobile Services and auto-scale them to so that they scale dynamically based on actual usage.