This topic shows you how to use Azure Mobile Services to leverage data in a Xamarin.iOS app. In this tutorial, you will download an app that stores data in memory, create a new mobile service, integrate the mobile service with the app, and then login to the Azure Management Portal to view changes to data made when running the app.

NOTE:

This tutorial is intended to help you better understand how Mobile Services enables you to use Azure to store and retrieve data from a Xamarin.iOS app. As such, this topic walks you through many of the steps that are completed for you in the Mobile Services quickstart. If this is your first experience with Mobile Services, consider first completing the tutorial Get started with Mobile Services.

IMPORTANT:

To complete this tutorial, you need an Azure account. If you don't have an account, you can create a free trial account in just a couple of minutes. For details, see Azure Free Trial.

Download the GetStartedWithData project

This tutorial is built on the GetStartedWithData app, which is a Xamarin.iOS app. The UI for this app is identical to the app generated by the Mobile Services Xamarin.iOS quickstart, except that added items are stored locally in memory.

In the Create a mobile service page, select Create a free 20 MB SQL Database, then type a subdomain name for the new mobile service in the URL textbox and wait for name verification. Once name verification completes, click the right arrow button to go to the next page.

This displays the Specify database settings page.

NOTE:

As part of this tutorial, you create a new SQL Database instance and server. You can reuse this new database and administer it as you would any other SQL Database instance. If you already have a database in the same region as the new mobile service, you can instead choose Use existing Database and then select that database. The use of a database in a different region is not recommended because of additional bandwidth costs and higher latencies.

In Name, type the name of the new database, then type Login name, which is the administrator login name for the new SQL Database server, type and confirm the password, and click the check button to complete the process.

NOTE:

When the password that you supply does not meet the minimum requirements or when there is a mismatch, a warning is displayed.

We recommend that you make a note of the administrator login name and password that you specify; you will need this information to reuse the SQL Database instance or the server in the future.

You have now created a new mobile service that can be used by your mobile apps. Next, you will add a new table in which to store app data. This table will be used by the app in place of the in-memory collection.

Add a new table to the mobile service

To be able to store app data in the new mobile service, you must first create a new table in the associated SQL Database instance.

In the Management Portal, click Mobile Services, and then click the mobile service that you just created.

Click the Data tab, then click +Create.

This displays the Create new table dialog.

In Table name type TodoItem, then click the check button.

This creates a new storage table TodoItem with the default permissions set, which means that any user of the app can access and change data in the table.

NOTE:

The same table name is used in Mobile Services quickstart. However, each table is created in a schema that is specific to a given mobile service. This is to prevent data collisions when multiple mobile services use the same database.

Click the new TodoItem table and verify that there are no data rows.

Click the Columns tab and verify that there is only a single id column, which is automatically created for you.

This is the minimum requirement for a table in Mobile Services.

NOTE:

When dynamic schema is enabled on your mobile service, new columns are created automatically when JSON objects are sent to the mobile service by an insert or update operation.

You are now ready to use the new mobile service as data storage for the app.

Update the app to use the mobile service for data access

Now that your mobile service is ready, you can update the app to store items in Mobile Services instead of the local collection.

If you don't already have Azure Mobile Services listed in the Components folder, you can get it by right-clicking Components, choosing Get More Components and then searching for Azure Mobile Services.

In the Solution view in Xamarin Studio, open the TodoService class and uncomment the following using statement:

using Microsoft.WindowsAzure.MobileServices;

In the Management Portal, click Mobile Services, and then click the mobile service you just created.

Click the Dashboard tab and make a note of the Site URL, then click Manage keys and make a note of the Application key.