Adding Azure Backend to Xamarin Mobile App

Screen Shot 2016-08-14 at 12.33.48 PM

With Microsoft Azure – the cloud computing service provided by Microsoft, it is easier than ever before to build a back-end to power your Xamarin mobile application. Moreover, Microsoft Azure provides simple no-code backends with Azure Easy Tables to help everyone  make it even more do-able. Let’s start!

Register Microsoft Azure

– Go to https://azure.microsoft.com to buy or register for a 30-day trial Microsoft Azure.
– After filling out all the required information, you are now ready to play with it.
– You can also sign up a free Azure account with Dreamspark (only available for students) and with MSDN subscription.

Screen Shot 2016-08-14 at 11.42.38 AM

Start a new Xamarin Project

– If you are using Windows, then download Microsoft Visual Studio with Xamarin extension. If you are using MacOS, then download Xamarin Studio.
– Open it up, start a new project or you can download sample solutions from Xamarin.

Screen Shot 2016-08-14 at 11.49.00 AM.png

Create an Azure Mobile App (Back-end)

You can simply create a no-code Azure Easy Tables backend in less than a minute with Mobile App Quickstart template.

– Log in to portal.azure.com
– Create a new Mobile Apps Quickstart, then follow the instruction to deploy it.

Screen Shot 2016-08-14 at 12.17.03 PM.png

– After that, select Easy Tables to upload or create your own data.

Screen Shot 2016-08-14 at 12.01.33 PM

Now, your backend is ready to go!!!

Implement Azure backend to Xamarin Mobile App

We will use Azure App Service Helpers library to add an Azure backend to our mobile app in just four lines of code.

Just simply add the App Service Helpers NuGet, initialize the library, pass in your Azure mobile app’s URL, register a data model as a table, and finalize the schema. Add these lines of code to App.cs in your project.

// 1. Create a new EasyMobileServiceClient.
AzureClient = EasyMobileServiceClient.Create();

// 2. Initialize the library with the URL of the Azure Mobile App you created in Step #1.
AzureClient.Initialize(https://YOUR-APP-NAME-HERE.azurewebsites.net);

// 3. Register a model with the EasyMobileServiceClient to create a table
AzureClient.RegisterTable();

// 4. Finalize the schema for our database. All table registrations must be done before this step.
AzureClient.FinalizeSchema();

Be sure to update YOUR-APP-NAME-HERE with the app name you just specified.

Now, we have implemented all of the code we need in our app! Amazing isn’t it! That’s it! App Service Helpers will automatically handle all communication with your Azure backend for you, do online/offline synchronization so your app works even when it’s not connected, and even automatic conflict resolution.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s