ADMIN

In my last article, I described how to use Visual Studio to create and deploy an Azure Mobile Service with server-side code written in a .NET language. I chose C# for that example. In this article, we will walk through the boilerplate C# code generated when you create a new Azure Mobile Services project.

TodoItem.cs

Next, we'll look at the TodoItem class (Listing 4), which can be found in DataObjects folder. This is the data model and will. It has 2 explicit properties - Text: the text of a Task that we need to complete; and Complete: a flag indicated whether or not we have completed this task. This object will will map to columns in the TodoItem table.
We don't need to explicitly provide an ID property because the class inherits this property from the EntityData class.

publicclass TodoItem : EntityData

{

publicstring Text { get; set; }

publicbool Complete { get; set; }

}

Listing 4

MobileServiceContext.cs

This is a Context used to manage database updates and retrievals via Entity Framework. It knows where to connect to the database and what model to send to the database. The Controller class will instantiate this to interact with the database table.

TodoItemController.cs

TodoItemController is the main controller class that maps HTTP Verbs (POST, PATCH, GET, and DELETE) to specific actions. It inherits from the TableController class, which has an IDomainManager named DomainManager that is used to retrieve and update data using Entity Framework. All the controller methods need to do is to call TableController methods, such as Lookup, UpdateAsync, InsertAsync, and DeleteAsync.

For example, if a client sends a request to our mobile service’s HTTP endpoint with the POST verb, the routing engine will run the PostTodItem method in TodoItemController (Listing 5).

public async Task<IHttpActionResult> PostTodoItem(TodoItem item)

{

TodoItem current = await InsertAsync(item);

return CreatedAtRoute("Tables", new { id = current.Id }, current);

}

To add business logic to your service, you will add code to the Controller methods (GetAllTodoItems, GetTodoItem, PatchTodoItem, PostTodoItem, and DeleteTodoItem.)

In this article, we covered the code that is automatically generated in a C# Azure Mobile Service.

In a previous article, I described how to create an Azure Mobile Service built on top of node.js - with all the server-side code written in JavaScript. You can also create a Mobile Service with server-side code written in C# or Visual Basic. You will probably prefer this method if you are more proficient in .NET than in JavaScript.

This article will walk you through the creation of an Azure Mobile Service, written in C#.

Launch Visual Studio 2013 and select File | New | Project from the menu. The New Project dialog displays, as shown in Figure 1.

Figure 1

Under the Templates list at the left of the dialog, expand either Visual Basic or C#; then, select the Cloud template category. Select "Azure Mobile Service" from the Cloud templates listed at the center of the dialog. Give the project a Name and Location and click the [OK] button.

The New ASP.NET Project dialog displays, as shown in Figure 2.

Figure 2

The Azure Mobile Service template should be selected and the "Web API" checkbox should be checked. Leave these selected and check and check the Host in the cloud checkbox; then, click the [OK] button.

Because you elected to host this service in the cloud, the Create Mobile Service dialog displays next, as shown in Figure 3.

Figure 3

Select an Azure subscription to deploy the Mobile Service; enter a name for your Mobile Service (it must be unique); select a Region; select a database; and enter login credentials for that database. Then click the [Create] button. This should create a project on your local machine and an empty Mobile Service in your Azure subscription.

The Mobile Service project is shown in Figure 4.

Figure 4

To publish your Mobile Service, right-click the project in the Solution Explorer and select Publish from the context menu. The "Publish Web" wizard displays with the "Profile" page activated as shown in Figure 5.

From the dropdown, select the Azure Mobile Service you created above and click the [Next] button.

The Profile page of the "Publish Web" wizard displays as shown in Figure 7.

Figure 7

Verify the information on the Profile page is correct and click the [Next] button.

The "Settings" page of the "Publish Web" wizard displays as shown in Figure 8.

Figure 8

Select "Release" from the Configuration dropdown and click the [Next] button.

The "Preview" page of the "Publish Web" wizard displays as shown in Figure 9.

Figure 9

Click the [Publish] button to publish the Mobile Service to your Azure subscription.

Now, you should be able to log onto the portal and view your new mobile service (Figure 10). Its status may be listed as “Creating…” if you go to the portal too quickly; but, within a couple minutes, you will be able to manage the service from the Azure portal.

Figure 10

You can manage this service almost exactly the same way that you managed a JavaScript mobile service. The difference is that the .NET mobile service does not contain a DATA tab. Data configuration in a .NET service is done in the Visual Studio project.

In this article, we showed the steps to create and publish a new Azure Mobile Service with server-side code in a .NET language.

Azure Mobile Services provides a simple way to expose server-side data to clients. In previous articles, we exposed data via a REST service and we created a client application that called that service to retrieve or update data.

But what if we want our service to push data down from the server to a client device without that device making a call each time? For example, you may want to tell send a message telling your app to change the text displayed on its tile, displaying the total number of orders entered in your e-commerce app; or you may want a "toast" popup notification to display on the app's device whenever someone scores in the Top 10 on a game you wrote.

We can use Push Notifications to do these things.

Each mobile vendor has its own service to manage Push Notifications and each service exposes an API to manage those notifications. Apple offers a Push Notification service to send data to registered iPhones and iPads; Google offers a Push Notification service to send data to registered Android phones and tablets; and Microsoft offers two Push Notification services - one to send data to registered Windows Pones and another to send data to registered Windows 8 or 8.1 devices.

Each of these services has an API and we can call each one explicitly for every device that will receive a notification. But this requires passing the address of each device, which is tedious and error-prone. Plus, it requires our server-side application to maintain a list of every device to which we want to push messages.

We can simplify the process by configuring Push Notifications through Azure Mobile Services. Azure Mobile Services Push Notifications automatically works with Azure Notification hubs to manage these messages.

In this article, we will focus on sending a Toast Notification to Windows 8.1 clients, but the process is similar for all Push Notifications.

The steps for setting up Push Notifications to a Windows 8.1 client using Azure Mobile Services are:

1. Create an Azure Mobile Service 2. Create a Windows 8.1 Client App and modify it as follows a. Associate app with store b. Get Package SID and Client ID from Live Services. Copy these to Mobile Service. c. Register notifications channel in OnLaunched (App.xaml.cs) d. Enable Toast notifications (Package.appxmanifest) 3. Update the Mobile Service service to send Push Notifications.

1. Create an Azure Mobile Service

2. Create a Windows 8.1 Client App and modify it as follows

For this example, we'll use the Windows 8.1 project in the Universal App generated for us in a previous article.

2a. Associate app with store

You will need a Windows Store account to complete this step. You can register at http://dev.windows.com/. It cost $19 to register for both the Windows Store and the Windows Phone Store and there is no annual renewal fee. Register your app with the store by opening the Visual Studio Solution; right-clicking on the Windows 8.1 project; and selecting Store | Associate App with the Store from the context menu. The "Associate App with the Windows Store" dialog (Figure 1) displays. Click the [Next] button.

Figure 1

If prompted, sign into the Windows Store (Figure 2)

Figure 2

You may be prompted for your email address (Figure 3). If so, enter it and click [Next]; then check your email account for a Security Code that was sent from the Microsoft Account Team.

Figure 3

Copy this code and paste it into Sign-In Wizard (Figure 4) and click the [Submit] button.

Figure 4

The "Select an app name" dialog (Figure 5) displays.

Figure 5

Enter a name for your app and click the [Reserve] button; then, click the [Next] button to display the final step in the wizard (Figure 6). Click the [Associate] button.

Figure 6

2b. Get Package SID and Client ID from Live Services. Copy these to Mobile Service.

Connect to the store portal (http://dev.windows.com for Windows Store apps and http://dev.windowsphone.com for Windows Phone apps) and click Dashboard. You should see your app listed with "In Progress" below its listing. Figure 7 shows the listing for an app in the Windows Store dashboard

Click the Live Services site link in the second paragraph to navigate to the Live Services page (Figure 10). You may be prompted to sign in again.

Figure 10

Note the Package SID and Client ID on the Live Services page. Copy each of these in turn and paste them into the appropriate fields of the "Windows Store" section of the "Push" page in the Azure Mobile Services page of the Azure portal. This is demonstrated in Figure 11.

Figure 11

Click the [Save] icon to save these values to your Mobile Service.

Your service is now capable of sending notifications to Windows store client apps.

2c. Register notifications channel in OnLaunched (App.xaml.cs)

Return to your .NET client application and open App.xaml.cs from the Shared project. Add the following 2 lines (Listing 1) to the top of this file:

1:using Windows.Networking.PushNotifications;

2:using Windows.UI.Popups;

Listing 1

Add the InitNotificationsAsync method to the bottom of the class (Listing 2)

2d. Enable Toast notifications (Package.appxmanifest)

In this example, the service will send a Toast notification, which will tell the client to popup a "Toast" message. A Toast message appears at the top-right of the Windows 8 screen and may contain 1 or more lines of text and an image.

To enable your application to accept Toast notifications, open the Package.appxmanifest file and select the "Application" tab. Under the Notifications section, select the "Toast capable" dropdown and set it to "Yes". (Figure 11)

Figure 12

Your client application is now listening for push notifications and capable of creating a Toast popup when it receives a notification.

3. Update the Mobile Service service to send Push Notifications.

The final step is to actually send Push Notifications from your Mobile Service. In this example, we will use the node.js mobile service we created in this article (link) and we'll send a Toast Notification to all Windows Store clients whenever a user enters a new ToDoItem.

In the Azure portal, open your Mobile Service and navigate to the todoitem table's SCRIPT page (Figure 12).

Figure 11

Select INSERT from the dropdown and replace the script with the code in Listing 3.

1: request.execute({

2: success: function() {

3:// If the insert succeeds, send a notification.

4: push.wns.send(null, payload, 'wns/toast', {

5: success: function(pushResponse) {

6: console.log("Sent push:", pushResponse);

7: request.respond();

8: },

9: error: function (pushResponse) {

10: console.log("Error Sending push:", pushResponse);

11: request.respond(500, { error: pushResponse });

12: }

13: });

14: }

15: });

16:

17: }

Listing 3

Test It Out

Your app is now ready to accept Push Notifications and your Mobile Service is configured to send them each time a new "ToDoItem" is inserted.

To see it in action, launch the application and insert a new ToDo item. Within a few seconds, you should see a "Toast" popup in the top right of your screen, indicating that you entered this item. If other users were also using this same app, they would see the same message.

In this article, we discussed Azure Mobile Services Push Notifications and walked through an example of adding them to a JavaScript Push Notification service and a Windows 8.1 application.

I had always heard good things about the St. Louis Days of .NET http://stldodn.com/2014, but this year was the first chance I had to attend. It did not disappoint. I didn't hear the final count, but the hallways at the Ameristar Casino Conference Center in St. Charles, MO were packed for this event.

A commitment in Houston caused me to miss the half-day workshops held on Thursday; but I arrived in St. Charles late Friday and I had a chance to mingle with many of the speakers after dinner. I liked the fact that the event drew from areas where I had a lot of contacts (Illinois, Indiana, Michigan) but also from parts of the country where I don't travel as often (e.g., Missouri, Kansas, Nebraska). Any chance I have to expand my network of smart people is a good thing.

Most speakers were from all across the Central Region but a few travelled from as far away as Philadelphia and Ottawa.

Microsoft was well-represented at the St. Louis Day of .NET. From DX (the division where I work), Bill Fink, Jennifer Marsman, Donovan Brown, Kevin Remde, Randy Pagels, and I all spoke at the conference. Jeff Fatic and Matt Winkler of Microsoft also delivered presentations.

I attended sessions on JavaScript, Azure, and Design and I learned something in every session. I also had a long conversation about Azure Notification Hubs with Azhar Salahuddin and Charlie Chapman. I have used Notification Hubs indirectly through Azure Mobile Services, but they showed me how they work under the hood and how to work directly with notification hubs

I also spent some time with Angela Dugan of Polaris Solutions picking her brain about how organizations can become more agile and with Charlie Chapman and Gus Emery talking about universal apps.

I learned a lot at the St. Louis Days of .NET and I also got a chance to get to know the communities in the western Midwest a little bit better.

The organizers were already planning to reprise St. Louis Days of .NET in 2015. I recommend you check it out.

In a previous article, I showed how to create a sample .NET client application to connect to your Azure Mobile Service. In this article, I will show you how to add authentication to this sample application.

Azure Mobile Services supports a number of different methods of authentication. A couple of them you would expect from a Microsoft platform - User can be authenticated against Active Directory or they can be directed to log in with a Microsoft account (formerly known as a "Live" account.) You would expect Mobile Services to support these authentication methods because they are created and/or maintained by Microsoft. However, Mobile Services is designed to accept authentication tokens that adhere to the OAuth standard and it is built to support Facebook, Twitter, and Google authentication - all of which conform to oAuth.

In order to use an Authentication Provider, you must enable support for that provider. You can enable support for one provider and instruct all clients to use that provider; or you can enable support for multiple oAuth providers and clients will be able to offer a choice to users, allowing them to log in with their favourite service.

Setting up each of these oAuth providers is pretty similar, so the best way to show you how is to walk through an example. I'll enable Twitter authentication but the process is not much different for other providers.

Creating An App on Twitter

In order to allow users to log into your app via Twitter, you need to create an app in Twitter. You can do so by navigating to http://dev.twitter.com and signing in with your Twitter credentials (you may need to create a Twitter account first. If so, you may be the last person on Earth to do so.) At the bottom of the page is a "Tools" section. Click the "Manage Your Apps" link in this section, as shown in Figure 1.

Figure 1

On the "Twitter Apps" page, click the [Create New App] button (Figure 2).

Figure 2

The "Create an application" page (Figure 3) displays. The first 3 fields are required.

Figure 3

At the "Name" field, enter a name for your application. I usually use the same name I gave my Azure Mobile Service.

At the "Description" field, enter a brief description of your app.

At the "Website" field, enter your Mobile Service URL. You can find this URL in the Azure portal on the DASHBOARD tab of your Mobile Service (Figure 4)

Figure 4

Scroll down the "Create an Application" page (Figure 5), read the Developer agreement completely (in this case, you are likely the first person ever to do this), check the "Yes I agree" checkbox, and click the [Create your Twitter application] button to create the app.

Figure 5

A page displays for your newly-created app with a tab menu across the top as shown in Figure 6.

Figure 6

Click the "Keys and Access Tokens" tab to display the Application Settings as shown in Figure 7.

Figure 7

You will need the Consumer Key (API Key) and the Consumer Secret (API Secret) so keep this web page open and open a new browser or browser tab and navigate to the Azure Portal.

In the Azure Portal, select your mobile service and click the IDENTITY menu option as shown in Figure 8.

Figure 8

On the IDENTITY page, scroll down to the "twitter settings" section. From the Twitter "Application Settings" page, copy the API Key and the API Secret and paste these values into the corresponding fields on the Azure Mobile Services IDENTITY page, as shown in Figure 9.

jFigure 9

Click the SAVE icon (Figure 10) at the bottom of the page to save these changes.

Figure 10

Your Mobile Service now supports Twitter authentication.

Force clients to login before accessing your service by setting permissions on the service actions. This is done at the Mobile Service table's PERMISSIONS page. (To access the PERMISSIONS page, select your Mobile Service in the Azure Portal; click the DATA tab; select the table you want to secure; and click the PERMISSIONS tab.)

Change the permission of each action to "Only Authenticated Users" by selecting "Only Authenticated Users" from the dropdown next to each action, as shown in Figure 11. Click the SAVE icon to commit these changes.

Figure 11

Now any client app that calls your service has no choice but to force users to log in with Twitter in order to use your app.

CLIENT APP

Open the client app that we created in an earlier article and open MainPage.cs in the Shared project.

Add the following code to the class.

1: MobileServiceUser user = null;

2:private async System.Threading.Tasks.Task AuthenticateAsync()

3: {

4:while (user == null)

5: {

6: user = await App.MobileService

7: .LoginAsync(MobileServiceAuthenticationProvider.Twitter);

8: }

9:

Listing 1

Then call this method by adding the following line at the top of the OnNavigatedTo method

1: await AuthenticateAsync();

Listing 2

When the user navigates to the MainPage, she will be redirected to the Twitter login page where she must successfully login before proceeding. The MobileService will remember the user and pass this information in a token with each request to the REST service. If you configure another authentication provider, such as Google or Microsoft, you can direct the user to that provider's login page by changing the MobileServiceAuthenticationProvider enum, which is passed as a parameter to the MobileService.LoginAsync method.

In this article, we saw how to configure single sign-on for our Azure Mobile Service.

By default, the service allows anyone with the Application Key to access this Mobile Service. This Application Key is generated automatically when the service is created. You can view the key by clicking to the "Manage Keys" icon (Figure 1) at the bottom of the Mobile Service Dashboard to display the "Manage Access Keys" dialog (Figure 2).

Figure 1

Figure 2

In the generated sample application, this access code is automatically passed to the constructor of the MobileServiceClient object that is instantiated in App.xaml.cs (Listing 1)

If you have created a table for your Mobile Service, you can click on the service's Data tab and manage the Permissions of that table by selecting the table and clicking the Permissions tab.

Here, you will see 4 dropdowns (Figure 3) - one for each operation you can perform on the table (INSERT, UPDATE, DELETE, and READ). For each of these operations, you can set one of the following permissions:

Everyone

Anybody with the Application Key

Only Authenticated Users

Only Scripts and Admins

Figure 3

Below is an explanation of each Permission option

Everyone

The service is not secured. Anyone who knows the URI can access the service operation. Set this on the READ PERMISSION and you will be able to open a browser, navigate to the table's URI and view the data in the table.

Anybody with the Application Key

This is the default permission. Any request must contain the Application Key in the HTTP Header of the request. The format is

X-ZUMO-APPLICATION:key

where keyis the Application Key of this Mobile Service.

As described above, the .NET MobileServiceClient class handles this automatically if we pass the Application Key into its constructor.

Only Authenticated Users

An authentication token from a trusted authentication provider must accompany the HTTP request to this REST service. In a future article, I will show you how to set up single sign-on with trusted authentication providers so that this token is added to each request.

Only Scripts and Admins

This allows an operation to be performed only by Administrators logged onto the Azure portal or by PowerShell scripts running directly on the Virtual Machine on which the Mobile Service is running.

You are free to set different permissions for each operation. For example, you could allow anyone to read data in your table; require the Application Key for updates; authenticated sign on for inserts; and only allow Admins and server scripts to delete data from the table.

In reality, you will likely pick a single security mechanism for the table and set all operations to this. You can then write server-side code to handle any differences between the services (allowing a user to only delete his own records, for example).

Conclusion

The permissions are for a given combination of endpoint (which, in this case, points to a table) and action (INSERT, UPDATE, DELETE, and READ). If you like, you could set a different permission for each action on this endpoint. For example, you could declare that anyone can read data; only those with the Application Key can update data; only Authenticated users can Insert a row; and Deleting data is reserved for scripts and Admins. To me, it makes more sense to keep the same permission for each action, unless you have a specific reason for changing it for a given action.

In this article, we showed how to set permissions on each action for a given Azure Mobile Services endpoint.

In my last article, I described how to use the Azure Mobile Services wizard to create a sample client application. In this article, we will look at the code created by this wizard.

I'll focus on the C#/XAML version of the sample app but all the principles apply for the HTML5/WinJS version as well.

Figure 1 shows the solution, which includes a Windows 8.1 project, a Windows Phone 8.1 project, and a project with files that are shared by the other two projects.

Figure 1

I always compile this app before running it, because that ensures that all NuGet packages are updated.

Because this is a Universal app, it contains both a Windows 8.1 and a Windows Phone 8.1 project. The two projects do pretty much the same thing but each has a user interface appropriate to its own platform.

A screen shot of each running app is shown in Figure 2 (Windows 8.1) and Figure 3 (Windows Phone 8.1). As you can see, this app keeps track of a user's To Do List. The list of "To Do Items" is stored in an Azure SQL Database, which is exposed via Azure Mobile Services.

Figure 2

Figure 3

Most of the interesting stuff happens in the Shared project.

TodoItem.cs

Let's look first at the Model. It is in the Shared project because both apps use the same model. You can find it in the TodoItem.cs file in the DataModel folder (Listing 1).

1:publicclass TodoItem

2: {

3:publicstring Id { get; set; }

4:

5: [JsonProperty(PropertyName = "text")]

6:publicstring Text { get; set; }

7:

8: [JsonProperty(PropertyName = "complete")]

9:publicbool Complete { get; set; }

10: }

Listing 1

The three properties (Id, Text, and Complete) will map to columns in the SQL Server table. Text and Complete are decorated with the JsonProperty attribute, which is found in the Newtonsoft.Json library and tells .NET how to name these properties when an object is transformed into the JSON format. Strictly speaking, this is unnecessary, but JSON objects tend to follow the
JavaScript convention of Camel casing.

App.xaml.cs

The shared App.xaml.cs takes care of some basic processing when an app starts up, suspends, or has a problem.

As far as Azure Mobile Services is concerned, the important line is the MobileService field declaration (Listing 2)

The second parameter of the constructor is the application key generated by your Mobile Service. Passing the Application Key to the constructor of our MobileServiceClient is necessary if we set permissions to only allow calls to the mobile service by clients that provide the Application Key. Whenever we call the REST service with this object, the Application Key will be passed in the header of HTTP calls to the mobile services endpoints.

This static class is available throughout the application and contains methods to communicate with your mobile service. Its main use is to create an IMobileServiceTable by calling the static object's GetTable() method, which is done in the MainPage.

MainPage.cs

Notice that all three projects contain the MainPage class, which derives from the Page object. In both the Windows project and in the Windows Phone project, this class is in the MainPage.xaml.cs file, while the class is in the MainPage.cs file in the shared project. Notice also that these are all "partial" classes and that each is in the same namespace. At compile time, both the Windows and Windows Phone projects will pull in the class from the Shared Project and use its code.

At the top of the MainPage class is the creation of two sets of our model (Listing 3).

MobileServiceCollection items is simply a collection on the client that is used to bind to a ListView control in our XAML named ListItems.

The IMobileServiceTable interface has methods to interact with the REST API specified when the MobileService was created (which is our Azure Mobile Service API). So, the todoTable object has implementations of these methods specific to our service.

For example, the InsertTodoItem method makes a call to todoTable.InsertAsync() and passes an instance of the TodoItem. This calls our Azure Mobile Service REST endpoint (in this case, that endpoint is https://giard.azure-mobile.net/Tables/todoitem), using the POST Verb and passing

We can use Lync extension methods of todoTable to retrieve specific data into the todoTable object as in Listing 4 (from the RefreshTodoItems() method), which retrieves only todoItems for which the Boolean field Complete is false.

1: items = await todoTable

2: .Where(todoItem => todoItem.Complete == false)

3: .ToCollectionAsync();

Listing 4

The shared code takes advantage of the fact that the events fired in Windows and in Windows Phone are very similar and that the similar objects with similar names and events are created in the MainPage.xaml of each project. Because of this, the shared project can even contain event handlers that are appropriate for either project. For example, Listing 5 is the event handler when you click a checkbox next to an item on either the phone or your Windows PC/Tablet to mark that item as "Complete".

Conclusion

Notice how much of the application logic was moved into the Shared project. This isn't surprising because both the Phone app and the Windows app do the same thing - but with different user interfaces. It should be your goal to push as much of our app as you can into the Shared project.

When you build your own app, you will almost certainly use a different model and a different user interface. However, the samples code in this generated application should provide you a template for how to do basic operations on your mobile service, such as Read, Write, Update, and Delete. Make sure you understand the sample; then copy the appropriate code into your application and modify it to fit your model.

In the last article, I showed how to create a new Azure Mobile Service in the portal. In this article, I will show you how to use the wizard to create an application, consisting of a new table, an HTTP endpoint to access that table, and a sample client application to access the data through that endpoint.

Log onto the Azure Portal and select the MOBILE SERVICES icon in the left menu. Figure 1 shows the Mobile Service we created last time.

Figure 1

Click the arrow next to the service name to display details about the service (Figure 2).

Figure 2

Notice the choices you have next to "CHOOSE A PLATFORM". The Platforms listed are the various client platforms explicitly supported by Mobile Services. Remember that Mobile Services exposes data via standard interfaces such as HTTP and JSON which can be used by a wide variety of platforms and languages. For this demo, click the "Windows" button; then expand the "CREATE A NEW WINDOWS APP" link. This will reveal the 3 steps to get you started building an application around Azure Mobile Services (Figure 3).

Figure 3

Get the tools (Figure 4) allows you to download a free version of Visual Studio. If you already have any version of Visual Studio 2013 installed, you can skip this step.

Figure 4

The "Create a table" step (Figure 5) allows you to create a sample SQL Server table. Click the green button to create a new table named "TodoItem" in your database with columns to keep track if the tasks you need to do today and whether you have completed each task.

Figure 5

The “Download and run your app” step (Figure 6) will generate client code that will connect to your application.

Figure 6

Select a language (C# or JavaScript) and click the Download button to download a ZIP file containing a Universal App that includes a Windows 8.1 project, a Windows Phone 8.1 project, and a Shared Code project. Depending on your language selection, these projects will either contain a user interface written in XAML and C# code-behind or an HTML5 front-end with a WinJS code-behind. Figure 7 shows the results of C#/XAML project generated by Azure Mobile Services.

Figure 7

Compile and run this app to see it in action. Figure 8 shows a screen shot of the Windows 8 app. You can enter a new task in the textbox and click Save to send data to the mobile service telling it to insert a row in the todoitem table. A list on the right displays all tasks that are not yet completed. Click the checkbox next to an item to send data to the mobile service telling it to update the todoitem table, setting the Complete column to FALSE.

Figure 8

Figure 9 shows the Windows Phone project running.

Figure 9

You can see that the apps look similar because they have the same functionality. The differences are related to the size, layout, and other considerations of the specific platform on which they run. Play with each app and you will see that they function about the same, thanks to the large percentage of shared code.

In this article, we saw how to run the Azure Mobile Services wizard to generate a sample table and client application.

With Azure Mobile Services, developers can quickly create a REST interface to read and write their backend database.

The Azure portal provides a wizard for creating a sample solution built around mobile services in just a few minutes. In this article, I will walk you through the steps to create a new Azure Mobile Service.

Log onto the Azure Portal and select the MOBILE SERVICES icon (Figure 1) in the left menu.

Figure 1

Click the NEW button at the bottom of the screen (Figure 2).

Figure 2

This exposes a menu (Figure 3).

Figure 3

With COMPUTE and MOBILE SERVICES selected (which should already be the case) click the CREATE button.

The "Create a Mobile Service" dialog (Figure 4) displays.

Figure 4

Give a name for the service. The full name will be whatever you type in the URL textbox, followed by ".azure-mobile.net" and it must be unique. The portal will let you know if someone else has chosen the same name. Select an existing database or create a new one; then select the Region where the Mobile Service will live. It makes sense to create the service in the same region where the database resides.

Finally, select the language in which to build the backend service. If you select JavaScript, the server-side solution will be hosted in Node.js. If you select .NET, you can create a solution in Visual Studio and deploy it to Azure, where it will be hosted in IIS.

Click the arrow (Figure 5) at the bottom right of the dialog to advance to the next page, where you can specify database information.

Figure 5

Figure 6 show the page if you elect to connect to an existing database. Select the database connection string; then enter the login name and password with which you will connect to this database.

Figure 6

Click the check button to create the Mobile Service. After a few seconds, the service will show up in the portal as in Figure 7.

Figure 7

In this article, we saw how to create a new Azure Mobile Service. In the next article, we will add a table and allow clients to retrieve and update data in that table, using this service.

Storing data in the cloud allows your application to remember information between launches and to share data among other users, applications, and devices.

Exposing that data via a REST interface makes this data accessible to applications running on a variety of platforms and written in a variety of languages. REST is an architectural pattern for allowing clients to read and update server data through a consistent API. The current implementations of REST uses an HTTP endpoint (a URL) to expose functionality and the features of HTTP (verbs, response codes, and header data) to exchange data between the client and the server.

Azure Mobile Services (ZuMo) makes it easier to expose your data as a REST endpoint by handling the "plumbing" code for you so that you can focus on your data model and your business logic.

With just a few clicks, you can create a service and map it to a database table. ZuMo will create an HTTP endpoint; map HTTP verbs to Create, Read, Update, and Delete methods; create those methods for you; and handle the transformation from JSON data into objects that map to rows in your database table. This isn't impossible code for you to write, but it can be a lot of code. And wouldn't your time be better spent writing the code that makes your application unique?

Azure Mobile Services will even generate a client application to call your new REST service and pass data to and from it. You can use this application as a starting point or you can copy and paste code from this app into your own client app. ZuMo is capable of generating a sample client application for Windows 8, Windows Phone, HTML and JavaScript, Xamarin, PhoneGap, Android, or iOS.

Azure Mobile Services is a true cross-platform solution that is simple to implement because it handles much of the plumbing code for you.

11/2 Today I am grateful for the friends I have kept for decades. They've known me at my best and at my worst.

11/1 Today I am grateful I finally caught up editing all my videos and photos.

10/31 Today I am grateful for dinner with my niece Amanda last night.

10/30 Today I am grateful for a home-cooked meal last night.

10/29 Today I am grateful for a chance to speak at the Motor City Software Testers last night & to all who came to hear me.

10/28 Today I am grateful I attended an exciting Monday Night Football game in Dallas last night.

10/27 Today I am grateful for some authentic Texas BBQ last night.

10/26 Today I am grateful for the students at TAMUHack who show energy, imagination, and passion and built so many great projects this weekend. I'm also grateful for the Michigan State Spartans, who drove through the michigan wolverines like a spike through grass yesterday!

10/25 Today I am grateful for my first trip to College Station, TX.

10/24 Today I am grateful I was invited to speak at the inaugural meeting of the Local Variables user group in South Bend, IN yesterday.

10/23 Today I am grateful for a long hot shower on a chilly morning.

10/22 Today I am grateful to God, who helped me through the difficult times in my life.

10/21 Today I am grateful for a day with few responsibilities.

10/20 Today I am grateful for a weekend in Indiana watching football with Tim Giard

10/18 Today I am grateful for lunch yesterday with Corey Haines

10/17 Today I am grateful for an unexpected gift from the Madison Mobile .NET Developers Group .

10/16 Today I am grateful for a successfully completed trip to Minnesota and Wisconsin.

10/15 Today I am grateful I completed 1 year at the best job I've ever had.

10/14 Today I am grateful for dinner last night with Brent Stineman

10/13 Today I am grateful for the open Wi-Fi that suddenly showed up when I'm in my apartment. I'm not sure if the apartment complex added a repeater or if I have a new neighbor, but I appreciate it.

10/12 The Hitchhiker's Guide to the Galaxy was published 35 years ago today! I am fortunate to have met the book's author before his passing.

10/11 Today I am grateful for dinner and drinks last night with Patricia and Gary.

10/10 Today I am grateful to the folks a the Schaumburg Microsoft .NET Technologies Meetup for inviting me to speak last night

10/9 Today I am grateful for a great audience yesterday at the first Azure Dev Camp in St. Louis.

10/8 Today I am grateful that my son called me yesterday just to say "Hi".

10/7 Today I am grateful to Velichka, who brought me chicken soup when I was sick.

10/6 Today I am grateful for 12+ hours sleep last night that I desperately needed.

10/5 Today I am grateful for dinner with friends, a ticket to the Nebraska game, and a Spartan victory!

I was aided by the fact that I use Das Blog as a blogging engine. This gave me two advantages: 1. I could select a Das Blog template from the Azure Web Site gallery, automatically configuring the appropriate settings for my site; and 2. Das Blog uses XML files instead of a database to store blog posts, so I was able to xcopy my entire blog to Azure.

The only real work was changing my DNS settings to point to Azure, which took a few minutes. I set the site to user the SHARED hosting plan, which lets me point a custom domain to it. More popular blogs (like yours) may need to use the BASIC or STANDARD Web Hosting Plan, but I stuck with the cheap one and it works fine for me.

The story here is what a non-story this migration was. My site was down less than an hour and most of that was because I messed up the DNS settings the first time. It is servicing requests just fine and I am saving money because this hosting plan is cheaper than what I paid to my old provider.

Currently, I'm not using any advanced features, such as Scaling, Autoscaling, and Web Jobs but those are available to me if I need them.

I love the simplicity of Azure Web Sites. If you are considering using Azure, this is a good place to start.