Traditionally, connecting apps on devices such as Windows Phone with data in the cloud could be a headache, with the process becoming more complicated if we wanted to make the data available to other platforms such as IOS. In the later stages of 2012 though, the Windows Azure team released a preview of Mobile Services which set out to take the pain away from this process.

Mobile Services allow you to create powerful back-ends for your mobile applications, by accomplishing a number of tasks, such as easily storing structured data within Azure, accessing this data within your apps, authenticating users against popular 3rd party services such as Facebook and sending push notifications to your end users.  Best of all, you can implement a Mobile Service and connect it to an app in just a few minutes!

In order to get started with Mobile Services and to integrate them into a Windows Store app, you will need a few things;

  • Windows Azure account. If you don’t have one is easy to get by signing up for a free trial here.
  • Access to the Mobile Services Preview by visiting the Preview Features page once you have your Windows Azure account.
  • Visual Studio 2012 which, thankfully if you haven’t got it, you can get the Express editions for Windows 8 / Windows Phone from here.
  • The Windows Azure Mobile Services SDK

Once you have all of the above setup, you are all set to create your first Mobile Service. 

Creating your first Mobile Service in just a couple of minutes

To begin, login to your Windows Azure Portal at http://www.windowsazure.com.  Add a new item by clicking on the ‘New’ link at the bottom left of your dashboard and choose to create a new Mobile Service as shown below.

clip_image002

Once you have signed up to the Preview you can create your first Mobile Service from the Windows Azure Portal

When creating a new service you will first need to give it a name (needs to be unique, so you may get prompted to enter another if it has already been taken), choose to create a new SQL Azure instance or use an existing one and the region in which your service will be deployed to. For the purposes of getting started choose to create a new SQL Azure instance and, for the region, I have chosen Northern Europe, but you can choose whichever region you feel is best suited to your needs.

On the second screen of settings for creating your service you will configure a few additional settings for your database, such as the username / password you want to use and which region you would like to use for it (in most cases you should use the same region as you chose for your Mobile Service itself in the previous step). Go ahead and set choose a suitable username / password.

clip_image004

Creating a Mobile Service only needs you to configure a few simple settings and only takes a couple of minutes!

After around 30 seconds you should now see it listed within your Azure Portal under the Mobile Services section. That’s it! You have just created a brand new Mobile Service, capable of connecting to multiple mobile device platforms, in less time that it takes to make a cup of coffee!

Connecting your new service to an app

Now it is time to add some data to your new service and to connect your new service to an app. Luckily for us, the team behind Mobile Services have thought of everything, and have provided a great quick start for you to do just that.

To access the quick start click on your new Mobile Service to get to the services’ home screen and you should see something like in the screenshot below. From here, you can choose to find simple step by step instructions on how to connect your Mobile Service to apps designed for Windows Store, Windows Phone or even IOS. You even get to choose to see a specific set of instructions to connect to an existing app as opposed to a brand new one, in case you need to connect an app you have already created to the cloud. Pretty cool huh?

clip_image006

I would encourage you now to choose a platform and to follow the instructions to create your first connected app, which just like creating your Mobile Service, will only take a few minutes. You even get to download working source code generated for you!

Once you have followed the straight-forward steps, it should become pretty clear to you how easy it is to actually connect to your service and retrieve / manipulate the data that is being stored as part of it. At its simplest the process is something like;

1. Create a table within your service. You don’t need to define any columns on a table, as the schema is dynamic and any required columns will be created when you add new records from within your app. New tables can be created by simply providing a name for the new table within the Data tab on your Mobile Service.

2. Add a reference to your Mobile Service from your app – literally a couple of lines of code. For a Windows Store app it would look something like this;

public static MobileServiceClient MobileService = new MobileServiceClient(
"https://yourmobileserviceurl.azure-mobile.net/",
"VSDFFFFLUbxWDDDDDPMKOdV31");

3. Add a class to your app to represent the data that each table within your Service will hold. For example, if you have created a table called ‘Item’, create an ‘Item’ class like the one below;

public class Item

{

public int Id { get; set; }

public string Text { get; set; }

}

4. Now all it takes to add some data to your table from your app is the following code, which not only inserts the data into your Mobile Service table but, as I mentioned earlier, will create any columns (in this case the ‘Text’ column), as required.

Item item = new Item { Text = "Awesome item" };
await App.MobileService.GetTable<Item>().InsertAsync(item);

As you can see, pushing and storing data from your app in your Mobile Service tables is incredibly simple and consuming the data held in Azure is just as easy.

More than just storage

Mobile Services are not just about providing storage for data in the cloud for your apps, although that is a key feature. Instead Azure Mobile Services are there to provide a backend for your app and that includes a new of services that simplify some of the common tasks you might face as a mobile app developer.

Authentication – With Mobile Services you don’t need to create and test custom authentication codes for your apps, instead enabling you to authenticate users of your app against popular services such as Facebook and Twitter. More details about this feature can be found at http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-users-dotnet/

Push Notifications – Previously, in order to add Push Notifications to your app, you may have needed to create and test infrastructure and custom code to support them. This need is removed and managed for you as part of Mobile Services and setting up Push Notifications that are triggered when a records in a table is added / updated / deleted, or on another custom schedule, is now ridiculously easy!

Author Bio

garyGary Pretty

Deputy Head of Programming, Mando Group

http://www.mandogroup.com
Gary Pretty is the Deputy Head of Programming at Mando Group, a leading digital agency specialising in creating enterprise web sites and RIAs. Gary works with technologies across the Microsoft stack, including Windows Azure, Sharepoint, ASP.NET and Windows Phone. Gary can be found on twitter @GaryPretty.

 

Find more Azure goodness at Stacked 2013 - it’s free!

Hopefully this article has provided a useful introduction to Mobile Services, but I have really only highlighted how to get started.

To find out more about Mobile Services, and some of the other cool happenings Windows Azure, register now to attend Stacked 2013, a totally free 1 day conference for developers based around Windows Azure. The day is going to feature speakers including Scott Klein from Microsoft US, Mike Taulty from Microsoft UK and Maarten Balliauw, Richard Conway and Andy Cross, 3 well known MVPs from the community.

It promises to be a fantastic day for everyone who attends will get a chance to network with the speakers and will also receive some SWAG as well.

Full details and registration can be found at http://stacked.thestack.co.uk