Azure Mobile Services

I’ve been working with Azure Mobile Services since last year. At first I thought it was just a back-end service, where I could store data from mobile devices, but it actually goes much further than that and this is what I would like to tell you to start the week.

If you’re already using Microsoft Azure platform, you may have noticed that many of the services are supported between them. For example, Azure Media Services uses Azure Storage to store assets, Azure Notification Hubs uses Azure Service Bus for sending notifications, and so on. Azure Mobile Services is a linked service to all those that facilitate: the hosting for Apis (on Azure Websites), data storage (Azure SQL Database by default), notifications to users (Azure Notification Hubs ) and identity management (Access Control). Initially Node.js appeared as backend, but now we can work with .NET, relying on ASP.NET Web APIs for the creation of Apis.

Getting Started

If you’re a .NET developer, the easiest way to start working with the service is through Visual Studio. When you select the New Project … option you can see a project called Azure Mobile Service in the Cloud section.

New Project Azure Mobile Service
New Project… > Azure Mobile Service

After choosing a name and location, a new window appears where the ASP.NET Web Api option is selected by default. This window also allows us to link the new project with a Mobile Services account on your Microsoft Azure account.

New ASP.NET Project Mobile Service Microsoft Azure account
Creación de un nuevo projecto ASP.NET Web Api asociado a una cuenta de Microsoft Azure

If you select the «Hosted in the cloud» checkbox, it automatically asks for information in order to create the new account.

Create mobile service from VS
Create Mobile Service diálogo

While the account in the cloud is provisioning in the background, we can see in the Solution Explorer window the typical structure of an ASP.NET Web API  application with sample code.

Mobile Service Project - Solution Explorer
Mobile Service Project – Solution Explorer
  • TodoItemController: your first controller which works with Azure Mobile Services. In it there are some differences for us: First, this class is not inherited from ApiController but TableController <>, where the entity on which it operates is specified. This base class belongs to Azure Mobile Services, which gives us a set of standard operations on the data storage and DomainManager class which is used to inject what is the source of data we want to work with (It uses EntityFramework SQL Azure Database by default).
  • TodoItem: in the sample code is the class on which the previous controller is based. It is inherited from EntityData because EntityFramework is used to access the database.
  • Microsoft.ServiceBus.MessagingPerformanceCounters.man: A number of counters are generated by default for Notification Hubs that may be useful to us, for example: the number of messages sent successfully and not, latency and so on.
  • SampleJob: Azure Mobile Services is supported on Azure Websites, so we can make use of WebJobs.
  • Services property: To make use of all the services that are linked together, we have a property called Services which allows us to log events, trigger notifications, and so on.

We can run the project locally and get a screen like this:

This mobile service is up and running
This mobile service is up and running

If we click on try it out we can see the methods exposed in TodoItemController and our SampleJob. We can use any program like Fiddler, Postman, Paw, among others without creating a client.

Mobile Service - Probando el servicio
Mobile Service – Probando el servicio

After making your tests, the last step is to publish. To do this, simply go back to Visual Studio and select the Publish … option on the project.

Mobile Service - Publish
Seleccionamos el proyecto con el botón derecho y hacemos clic sobre Publish…

If you paired your solution with an account of Azure Mobile Services in the first step, the configuration would be completed from the beginning, so we just have to click the Publish button to deploy it. When the process is complete the browser launches with the same page that we saw in the previous step, although in this case we need to use credentials to access the test page. The credentials are a blank username and  the APPLICATION KEY is used as a password, for which we have to access the portal, select the service account and click on MANAGE KEYS.
Mobile Services - Manage Access Keys

With this post you have a basic understanding about getting started with Azure Mobile Services.

Cheers!