# Friday, November 28, 2014

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.

Let's walk through an example.

1. Create an Azure Mobile Service

For our example, we'll use the Azure Mobile Service we created in a previous article

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.

Zumo7-Figure 01 - Associate App 
Figure 1

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

Zumo7-Figure 02 - Sign In 
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.

Zumo7-Figure 03 - Sign In 
Figure 3

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

Zumo7-Figure 04 - Sign In 
Figure 4

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

Zumo7-Figure 05 - Select App Name 
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.

Zumo7-Figure 06 - Associate App
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

Zumo7-Figure 07 - DevCenter Dashboard 
Figure 7

Click the [Edit] link below your app to display the Submissions Details page (Figure 8).

Zumo7-Figure 08 - App Details
Figure 8

So far, you have only completed Step 1 (Reserve App Name) of the app submission process. Click step 2 (Services) to display the app's Services page (Figure 9)

Zumo7-Figure 09 - App Services 
Figure 9

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.

Zumo7-Figure 10 - Live Services
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.

 Zumo7-Figure 11 - Azure Push
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)

   1: private async void InitNotificationsAsync()
   2: {
   3:     // Request a push notification channel.
   4:     var channel = await PushNotificationChannelManager
   5:         .CreatePushNotificationChannelForApplicationAsync();
   6:  
   7:     // Register for notifications using the new channel
   8:     System.Exception exception = null;
   9:     try
  10:     {
  11:         await MobileService.GetPush().RegisterNativeAsync(channel.Uri);
  12:     }
  13:     catch (System.Exception ex)
  14:     {
  15:         exception = ex;
  16:     }
  17:     if (exception != null)
  18:     {
  19:         var dialog = new MessageDialog(exception.Message, "Registering Channel URI");
  20:         dialog.Commands.Add(new UICommand("OK"));
  21:         await dialog.ShowAsync();
  22:     }
  23: }

Listing 2

Your client application is now listening for push notifications.

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)

Zumo7-Figure 12 - Enable Toast
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). 

Zumo7-Figure 13 - Insert Script
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.

Friday, November 28, 2014 11:07:00 AM (GMT Standard Time, UTC+00:00)
# Sunday, November 9, 2014

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 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.

Zumo6-Figure 01 - DevTwitter
Figure 1

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

Zumo6-Figure 02 - Create New App button
Figure 2

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

Zumo6-Figure 03 - Create An Application 
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)

Zumo6-Figure 04 - Mobile Service URL

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.

Zumo6-Figure 05 - Developer Agreement

Figure 5

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

Zumo6-Figure 06 - Twitter App tabs 
Figure 6

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

Zumo6-Figure 07 - Twitter Keys 
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.

Zumo6-Figure 08 - Mobile Services IDENTITY menu 
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.

Zumo6-Figure 09 - Twitter Settings
Figure 9

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

Zumo6-Figure 10 - Save

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.

Zumo6-Figure 11 - Table Permssions
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.

Sunday, November 9, 2014 10:00:00 AM (GMT Standard Time, UTC+00:00)
# Saturday, November 8, 2014

In previous articles, I showed how to set up a new Azure Mobile Service and how to generate a sample application.

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 Acccess Keys" dialog (Figure 2).

Zumo5-Figure 01 - Manage Keys
Figure 1

Zumo5-Figure 02 - Manage Keys
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)

   1: public static MobileServiceClient MobileService = new MobileServiceClient(
   2:     "https://giard.azure-mobile.net/",
   3:     "MqJSWTxyZlOTRHdABCGOuDcQcTVqvR41"
   4: );

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 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

Zumo5-Figure 03 - Permissions
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 key is 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.

Saturday, November 8, 2014 10:00:00 AM (GMT Standard Time, UTC+00:00)
# Friday, November 7, 2014

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.

Zumo4-Figure 01 - Client App
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 app while it’s running 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.

Zumo4-Figure 02 - Running Win81 App
Figure 2

Zumo4-Figure 03 - Running Win81 App
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: public class TodoItem
   2: {
   3:     public string Id { get; set; }
   4:  
   5:     [JsonProperty(PropertyName = "text")]
   6:     public string Text { get; set; }
   7:  
   8:     [JsonProperty(PropertyName = "complete")]
   9:     public bool 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)

   1: public static MobileServiceClient MobileService = new MobileServiceClient(
   2:     "https://giard.azure-mobile.net/",
   3:     "MqJSWTabZlOTRHeFXPRBADoQcVtqvE41"
   4: );
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).

   1: private MobileServiceCollection<TodoItem, TodoItem> items;
   2: private IMobileServiceTable<TodoItem> todoTable = App.MobileService.GetTable<TodoItem>();

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".

   1: private async void CheckBoxComplete_Checked(object sender, RoutedEventArgs e)
   2: {
   3:     CheckBox cb = (CheckBox)sender;
   4:     TodoItem item = cb.DataContext as TodoItem;
   5:     await UpdateCheckedTodoItem(item);
   6: }

Listing 5

This event handler passes the checked item to the UpdateCheckedTodoItem method, which uses the todoTable object to call the REST endpoint (Listing 6).

   1: private async Task UpdateCheckedTodoItem(TodoItem item)
   2: {
   3:     // This code takes a freshly completed TodoItem and updates the database. When the MobileService 
   4:     // responds, the item is removed from the list 
   5:     await todoTable.UpdateAsync(item);
   6:     items.Remove(item);
   7:     ListItems.Focus(Windows.UI.Xaml.FocusState.Unfocused);
   8: }

Listing 6

The entire MainPage class is shown in Listing 7.

   1: sealed partial class MainPage: Page
   2: {
   3:     private MobileServiceCollection<TodoItem, TodoItem> items;
   4:     private IMobileServiceTable<TodoItem> todoTable = App.MobileService.GetTable<TodoItem>();
   5:  
   6:     public MainPage()
   7:     {
   8:         this.InitializeComponent();
   9:     }
  10:  
  11:     private async Task InsertTodoItem(TodoItem todoItem)
  12:     {
  13:         // This code inserts a new TodoItem into the database. When the operation completes
  14:         // and Mobile Services has assigned an Id, the item is added to the CollectionView
  15:         await todoTable.InsertAsync(todoItem);
  16:         items.Add(todoItem);
  17:     }
  18:  
  19:     private async Task RefreshTodoItems()
  20:     {
  21:         MobileServiceInvalidOperationException exception = null;
  22:         try
  23:         {
  24:             // This code refreshes the entries in the list view by querying the TodoItems table.
  25:             // The query excludes completed TodoItems
  26:             items = await todoTable
  27:                 .Where(todoItem => todoItem.Complete == false)
  28:                 .ToCollectionAsync();
  29:         }
  30:         catch (MobileServiceInvalidOperationException e)
  31:         {
  32:             exception = e;
  33:         }
  34:  
  35:         if (exception != null)
  36:         {
  37:             await new MessageDialog(exception.Message, "Error loading items").ShowAsync();
  38:         }
  39:         else
  40:         {
  41:             ListItems.ItemsSource = items;
  42:             this.ButtonSave.IsEnabled = true;
  43:         }
  44:     }
  45:  
  46:     private async Task UpdateCheckedTodoItem(TodoItem item)
  47:     {
  48:         // This code takes a freshly completed TodoItem and updates the database. When the MobileService 
  49:         // responds, the item is removed from the list 
  50:         await todoTable.UpdateAsync(item);
  51:         items.Remove(item);
  52:         ListItems.Focus(Windows.UI.Xaml.FocusState.Unfocused);
  53:     }
  54:  
  55:     private async void ButtonRefresh_Click(object sender, RoutedEventArgs e)
  56:     {
  57:         await RefreshTodoItems();
  58:     }
  59:  
  60:     private async void ButtonSave_Click(object sender, RoutedEventArgs e)
  61:     {
  62:         var todoItem = new TodoItem { Text = TextInput.Text };
  63:         await InsertTodoItem(todoItem);
  64:     }
  65:  
  66:     private async void CheckBoxComplete_Checked(object sender, RoutedEventArgs e)
  67:     {
  68:         CheckBox cb = (CheckBox)sender;
  69:         TodoItem item = cb.DataContext as TodoItem;
  70:         await UpdateCheckedTodoItem(item);
  71:     }
  72:  
  73:     protected override async void OnNavigatedTo(NavigationEventArgs e)
  74:     {
  75:         await RefreshTodoItems();
  76:     }
  77: }

Listing 7

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 app, it is likely that you will use a different model and a different 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.

Friday, November 7, 2014 10:00:00 AM (GMT Standard Time, UTC+00:00)
# Thursday, November 6, 2014

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.

Zumo2-Figure 01 - List Service
Figure 1

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

Zumo2-Figure 02 - GET STARTED
Figure 2

Notice the choices you have next to "CHOOSE A PLATFORM". These are some of the platforms supported by Azure Mobile Services. 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).

Zumo2-Figure 03 - GET STARTED
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.

Zumo2-Figure 04 - Get the Tools
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 track "To Do" items and whether they are complete.

Zumo2-Figure 05 - Create Table
Figure 5

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

Zumo2-Figure 06 - Download App
Figure 6

Select the language 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.

Zumo2-Figure 07 - Client App
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 "ToDo" item 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.

Zumo2-Figure 08 - Running App
Figure 8

Figure 9 shows the Windows Phone project running.

Zumo2-Figure 09 - Running App
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.

Thursday, November 6, 2014 10:00:00 AM (GMT Standard Time, UTC+00:00)
# Wednesday, November 5, 2014

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.

Zumo2-Figure 01
Figure 1

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

Zumo2-Figure 02 - New Button 
Figure 2

This exposes a menu (Figure 3).

Zumo2-Figure 03 - Create
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.

Zumo2-Figure 04 - Create
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.

Zumo2-Figure 05 - Next
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.

Zumo2-Figure 06 - DB
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.

Zumo2-Figure 07 - New Service
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.

Wednesday, November 5, 2014 10:00:00 AM (GMT Standard Time, UTC+00:00)
# Tuesday, November 4, 2014

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

Exposing that data via a REST interface makes it 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 power 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 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 horrific code 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?

ZuMo 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.

Tuesday, November 4, 2014 10:00:00 AM (GMT Standard Time, UTC+00:00)
# Saturday, October 18, 2014

What is Demand Elasticity, how does it affect my apps, why should I care, and how does Azure address this?

Demand Elasticity is an issue because almost no app has a constant demand over time: Some apps are used primarily during business hours and very little during the night; some apps have abnormally high demand during specific events, such as the launch of a new product or while NFL games are broadcasting; some businesses have peak seasons when they do nearly all their business (I once worked for an electronics retail store that earned over 80% of their revenue between Thanksgiving and New Years Day.)

Each of the above examples describes demand variability that you can plan for. An even more difficult problem is unexpected changes in demand. Imagine if a popular TV show recommends your online service. Demand would likely skyrocket. Could your services handle this extra, unexpected load?

Because of this change in demand, you need to decide how much hardware to deploy for your application. If you deploy too much hardware, you are wasting your money, but if you deploy too little, you will miss out on potential users and revenue. And in the fact that hardware is not easy or quick to deploy - It may take your organization weeks or months to respond to a sudden, unexpected increase in demand. And what do you do with that extra hardware when demand falls? For most organizations, it's not practical to buy and sell hardware as demand goes up and down.

Ideally, as demand increases and places higher load on your servers, you would increase the amount of hardware to which your application is deployed. Then, you would remove that hardware (and stop paying for it) as demand and workload decrease.  If you are managing and deploying the hardware yourself, this is not really practical. There is no quick market to buy and sell servers and most organizations take days – if not weeks – to provision a new server.

But Azure allows you to deploy more servers to your application and it automatically deploys them for you in a matter of minutes. Most services in Azure have a setting that allows you to change the number of running instances. This can be the number of web sites, web roles, mobile service, virtual machines, or dozens of other service instances available.

Below is the setting for configuring the number of instances of an Azure Web Site.
Scale-1
figure 1

Some services even allow you to automate this process. For example, you can configure Azure to monitor the CPU used by your web sites and automatically deploy a new instance of your site when CPU rises above a certain percent and remove an instance when it falls below a given percent. You can set a minimum and maximum to keep the number of instances within this range.

For Azure Web Sites, this Auto-scaling feature is available if we select the "Standard" hosting plan. Below are the controls that allows you to set these configuration.
Scale-2

Figure 2

Scaling up helps your service deal with extra usage (planned or unplanned), while scaling down helps you save money. The quicker you can do both, the more agile you will be.

Azure allows you the flexibility to scale up and down to meet changing demand.

Saturday, October 18, 2014 2:34:45 PM (GMT Daylight Time, UTC+01:00)
# Monday, September 8, 2014
Monday, September 8, 2014 4:54:37 AM (GMT Daylight Time, UTC+01:00)
# Friday, May 23, 2014

Starting a software company involves a lot of risk, including (but not limited to) financial risk, technology risk, market risk, and timing risk. Microsoft is actively trying to remove at least some of the risk for startup companies who are developing a software product or service. Because the first few years of a company tend to have the highest risk, Microsoft is offering the BizSpark program to mitigate that extra risk until a company stabilizes. The BizSpark program is designed to provide free software, free cloud computing hour, and free access to technical resources to qualified startups.

Specific benefits of the BizSpark program are:

  1. Free Microsoft software, including Windows, Visual Studio, SQL Server, Office, and many more. BizSpark members can download many thousands of dollars worth of software for free for 3 years
  2. $150 a month of Microsoft Azure cloud computing hours. If you are not familiar with Azure, check out http://azure.microsoft.com/en-us/ to see all the services that are available. There are too many Azure services to describe here, but startups often find Web Sites, Virtual Machines, and Azure Mobile Services useful in promoting or integrating with their products. If your demand increases, beyond this, there is even a chance to increase this to $5000 per month for one year.
  3. Free access to technical resources, such as Microsoft Technical Evangelists. Your local evangelist likely has regular office hours and can help you troubleshoot some of your technical issues.

There is absolutely no obligation or cost to joining the BizSpark program. At the end of the 3 years, you keep the software you have installed. There is no fee for the program and obligation to buy more software or Azure hours (although, we certainly hope that you do.)

To qualify, the company must meet the following criteria

  1. The company must be engaged in building a software product or service
  2. The company must be privately held
  3. The company must be less than 5 years old
  4. Annual revenues must not exceed $1 million.

More details about the BizSpark program are available at http://www.microsoft.com/bizspark/.

In the past, a startup was required to apply to the BizSpark program and wait for a response from Microsoft (sometimes for over a week). Now, however, I can provide a code to eligible startups that registers them in the BizSpark program immediately.

If you meet the above criteria and you would like to take advantage of the program, reach out to to your local Technical Evangelist (If you are in Wisconsin, Illinois, or Indiana, that is me) and describe your startup’s product.

Friday, May 23, 2014 3:03:01 AM (GMT Daylight Time, UTC+01:00)
# Monday, May 5, 2014
Monday, May 5, 2014 9:28:00 PM (GMT Daylight Time, UTC+01:00)
# Monday, April 21, 2014
Monday, April 21, 2014 11:01:22 PM (GMT Daylight Time, UTC+01:00)
# Thursday, April 3, 2014

Like Day 1, there were a number of big announcements from Microsoft during the Day 2 keynote at the Build conference. The most exciting parts were the new features of Windows Azure (now “Microsoft Azure”), as that team continues to push out new features at an impressive rate.

My notes from the Day 2 Keynote are below. Just like yesterday, these are just my raw notes and it’s possible I missed or misheard or mistyped something. So back off, ok? ;)

Azure
    Create, Delete, Manage Azure VMs from within Visual Studio
    Enable Remote .NET Debugging on VM
    Use Puppet to manage Azure VMs
    Intelligent Routing with Traffic Manager
        Route user to closest data center
        Manage failover
    Provision Azure from Visual Studio
    Powershell editor in Visual Studio
        Azure deployment scripts
    Browser Link
        2-way communication between VS and any web browser
    Web Jobs
        Run Background tasks
        Web Jobs SDK
    Free SSL certificate with every web site instance
    Publish code from VS to Azure Mobile Services
    Single Sign on with Active Directory
    Enable Java on Azure
    SQL Azure
        Max SQL Database size 500GB (was 150GB max)
        Automatic backups
        Self-service restore
            roll back db to point in time
            Built-in feature. On by default
        Active geo replication
            Primary DB in read-write mode
            Secondary in Read-only mode
            In case of catastrophe, you can initiate failover
.NET and C#
    Visual Studio suggests refactoring
    Roslyn project is now Open Source
    Xamarin can use Roslyn Compiler
New Azure Portal
    Service Health
        Snapshot of global health of data centers
        Drill down via "blades" - flyout panels
    Visual Studio online integrated into Azure portal
        Team project
        Automated builds
        Source control
        Edit code in browser (syntax highlighting)
        Check in changed code
        Azure Resource Manager

Thursday, April 3, 2014 8:48:32 PM (GMT Daylight Time, UTC+01:00)
# Monday, February 24, 2014
Monday, February 24, 2014 6:01:00 PM (GMT Standard Time, UTC+00:00)
# Monday, January 20, 2014
Monday, January 20, 2014 10:22:00 PM (GMT Standard Time, UTC+00:00)
# Monday, May 27, 2013
Monday, May 27, 2013 7:08:00 PM (GMT Daylight Time, UTC+01:00)
# Monday, May 6, 2013
Monday, May 6, 2013 10:08:00 PM (GMT Daylight Time, UTC+01:00)
# Tuesday, April 9, 2013
Tuesday, April 9, 2013 6:50:00 AM (GMT Daylight Time, UTC+01:00)
# Tuesday, April 2, 2013
Tuesday, April 2, 2013 6:44:00 AM (GMT Daylight Time, UTC+01:00)
# Thursday, February 28, 2013

In this screencast, I show how to create an Azure Virtual Machine.

Azure | Video
Thursday, February 28, 2013 3:28:00 PM (GMT Standard Time, UTC+00:00)
# Thursday, February 21, 2013

In this screencast, I show how to create an Azure Virtual Machine.

Azure | Video
Thursday, February 21, 2013 8:28:00 PM (GMT Standard Time, UTC+00:00)
# Saturday, February 16, 2013

In this screencast, I show 3 ways to create a Windows Azure web site.

Azure | GCast
Saturday, February 16, 2013 3:46:12 AM (GMT Standard Time, UTC+00:00)
# Monday, December 17, 2012
Monday, December 17, 2012 3:13:00 PM (GMT Standard Time, UTC+00:00)
# Monday, December 10, 2012
Monday, December 10, 2012 3:46:00 PM (GMT Standard Time, UTC+00:00)
# Thursday, September 27, 2012

Azure In Action by Brian Prince and Chris Hay has something for everyone. It provides a good overview of the use cases for Windows Azure and a high-level overview of the Azure architecture, which is useful for those new to the platform. It also provides many in-depth examples of Azure features, such as web roles, worker roles, and storage options.

The book also benefits from the light-hearted style of Prince and Ray, who are as entertaining in print as they are in person.

The only downside is that newer Azure features are not covered in this book and Microsoft is adding new features at a startling rate. As far as I know, no updated edition is in the works to cover these new features.

Still, the book remains relevant because of its focus on the uses of cloud computing and on the still-relevant core features.

If you are new to Windows Azure, this book is a good starting point.

Azure | Books
Thursday, September 27, 2012 3:38:30 PM (GMT Daylight Time, UTC+01:00)
# Monday, September 3, 2012
Monday, September 3, 2012 5:29:02 PM (GMT Daylight Time, UTC+01:00)
# Monday, August 27, 2012
Monday, August 27, 2012 11:54:00 PM (GMT Daylight Time, UTC+01:00)
# Sunday, August 12, 2012

I recently delivered a presentation titled “Persistence in the Cloud: How to Use Azure Storage” at the aspconf online conference. A recording of this presentation is available at http://channel9.msdn.com/Events/aspConf/aspConf/Persistence-In-The-Cloud-How-to-use-Azure-Storage.

Sunday, August 12, 2012 5:52:59 PM (GMT Daylight Time, UTC+01:00)
# Friday, July 20, 2012

Here is a video of the Azure Q&A Experts Panel at the 2012 Detroit Day of Azure.

Friday, July 20, 2012 3:00:00 PM (GMT Daylight Time, UTC+01:00)
# Thursday, July 19, 2012

Here is a video of Dennis Burton's Single Page, Real Time Web Apps Using Node.js And Windows Azure presentation at the 2012 Detroit Day of Azure.

Thursday, July 19, 2012 3:00:00 PM (GMT Daylight Time, UTC+01:00)

Here is a video of Eric Boyd's BI In The Cloud With SQL Azure Reporting presentation at the 2012 Detroit Day of Azure.

Azure | Video
Thursday, July 19, 2012 2:55:00 PM (GMT Daylight Time, UTC+01:00)
# Wednesday, July 18, 2012

Yesterday, I had the pleasure of presenting at the aspconf online conference. I delivered 2 presentations: HTML5 is the Future of the Web; and Using Windows Azure Storage.

As promised, my slides and demos are available by clicking the links below.

   
Wednesday, July 18, 2012 3:43:00 PM (GMT Daylight Time, UTC+01:00)
# Tuesday, July 17, 2012

Here is a video of Jason Follas's Using Geospatial Data With SQL Azure presentation at the 2012 Detroit Day of Azure.

Tuesday, July 17, 2012 3:00:00 PM (GMT Daylight Time, UTC+01:00)
# Sunday, July 15, 2012

Here is a video of Michael Collier's Windows Phone 7 And Windows Azure – A Match Made In The Cloud presentation at the 2012 Detroit Day of Azure.

Sunday, July 15, 2012 3:21:00 PM (GMT Daylight Time, UTC+01:00)
# Saturday, July 14, 2012

Here is a video of Mark Stanislav's Cloud Disaster Recovery presentation at the 2012 Detroit Day of Azure.

Saturday, July 14, 2012 3:20:00 PM (GMT Daylight Time, UTC+01:00)
# Friday, July 13, 2012

Here is a video of Brian Prince's Architectural Patterns For The Cloud presentation at the 2012 Detroit Day of Azure.

Friday, July 13, 2012 3:17:00 PM (GMT Daylight Time, UTC+01:00)
# Thursday, June 14, 2012

Here is a video of Michael Collier's "The Hybrid Windows Azure Application" presentation at the 2012 Detroit Day of Azure.

Azure | Video
Thursday, June 14, 2012 3:43:00 PM (GMT Daylight Time, UTC+01:00)
# Wednesday, June 13, 2012

Here is a video of Joe Kunk "Windows Azure Data Marketplace" presentation at the 2012 Detroit Day of Azure.

Azure | Video
Wednesday, June 13, 2012 3:29:00 PM (GMT Daylight Time, UTC+01:00)
# Tuesday, June 12, 2012

Here is a video of John Ferringer's "Office 365" presentation at the 2012 Detroit Day of Azure.

Azure | Video
Tuesday, June 12, 2012 3:28:00 PM (GMT Daylight Time, UTC+01:00)
# Sunday, June 10, 2012

Here is a video of Jennifer Marsman's "Writing Your First Azure App" presentation at the 2012 Detroit Day of Azure.

Azure | Video
Sunday, June 10, 2012 4:26:00 PM (GMT Daylight Time, UTC+01:00)
# Saturday, June 9, 2012

Here is a video of Jennifer Marsman's "Azure 101" presentation at the 2012 Detroit Day of Azure.

Azure | Video
Saturday, June 9, 2012 7:22:00 PM (GMT Daylight Time, UTC+01:00)
# Friday, June 8, 2012

Here is a recording of Brent Stineman’s keynote presentation at the 2012 Detroit Day of Azure.

Azure | Video
Friday, June 8, 2012 5:55:00 PM (GMT Daylight Time, UTC+01:00)
# Wednesday, May 2, 2012
Wednesday, May 2, 2012 5:56:00 PM (GMT Daylight Time, UTC+01:00)
# Monday, April 16, 2012
Monday, April 16, 2012 4:02:00 PM (GMT Daylight Time, UTC+01:00)
# Tuesday, March 20, 2012

Cloud computing has been a hot topic in the software industry for the past couple years. Many of us hear about cloud technologies such as Windows Azure, but don't know how to get started.

I wanted to make it easy to find that information, so I'm organizing a 1-day conference to teach people about Windows Azure.

The Detroit Day of Azure will take place Saturday March 24 from 8AM to 6PM at the Microsoft office in Southfield, MI.

14 speakers from 8 different states have agreed to deliver 19 presentations at this event. The speakers (listed below) are among the foremost Azure experts in the region. The list includes MVPs, Microsoft insiders, book authors, and people delivering real Azure solutions for their customers.

Dennis Burton
Michael Collier
Jason Follas
John Ferringer
David Giard
Joe Kunk
Jennifer Marsman
Jeff Nuckolls
Brian Prince
Mark Stanislav
Brent Stineman
Mike Wood
Chander Dhall
Eric Boyd

Azure MVP and Sogeti National Cloud Computing Lead Brent Stineman will deliver the keynote; then we will split into 3 rooms for the rest of the day, where you can choose from several great topics and speakers. Our plans are to record at least some of the conference on video. We may even live stream some of it, but that is still in the planning phase.

We will designate one room for programmers to build Azure applications. Attendees can bring a laptop and either work on their own project or work through the Azure labs, which we will provide for you. Many smart people will be around if you get stuck. Remember to download and install the Azure SDK and sign up for a free Azure Trial before you arrive!

Download Azure SDK
Sign Up for Free Azure Trial

As with any successful event, many people helped out. Onorio Catenacci, Jamie Altizer, Matt Ruma, Shelly Noll, Sukhdev Tur, Justin Baker, Akhil Mahajan, Brian Korzynski, Jelard Macalino, Jim Priore, and Falicia Starr have volunteered their time to help; while Microsoft, Sogeti, The Epitec Group, Telerik, and RIIS donated their money; while Pluralsight, Wrox, and O'Reilly donated products to give away.

If you have been attending the Great Lakes Area .NET User Group (where I was president the last two years), you won't be surprised to learn that we are serving some excellent food at this event. Included in the $20 admission cost is a continental breakfast and a buffet lunch from Lockhart’s barbeque in Royal Oak. We will also have some door prizes to give away at the end of the day.

More information on the Detroit Day of Azure is available at http://DetroitDayOfAzure.com. You can register at http://DayOfAzure.eventbrite.com/.

Space is limited and only a few tickets remain.

I'm very excited about this event and looking forward to it as an organizer, as a speaker, and as an attendee.

Tuesday, March 20, 2012 5:45:12 AM (GMT Standard Time, UTC+00:00)
# Tuesday, January 3, 2012
Tuesday, January 3, 2012 2:54:00 AM (GMT Standard Time, UTC+00:00)
# Tuesday, June 21, 2011

At the June 15 meeting of the Great Lakes Area .Net Users Group, Microsoft Developer Evangelist Brian Prince delivered a presentation titled “A Lap Around Windows Azure”.

Here is that presentation:

Tuesday, June 21, 2011 5:53:26 PM (GMT Daylight Time, UTC+01:00)
# Tuesday, March 29, 2011
Tuesday, March 29, 2011 10:02:00 AM (GMT Daylight Time, UTC+01:00)
# Thursday, August 19, 2010
Thursday, August 19, 2010 1:41:00 AM (GMT Daylight Time, UTC+01:00)
# Wednesday, July 8, 2009

Episode 32

In this video, author and speaker Josef Finsel describes moving databases to "The Cloud" using Azure Table storage.  You can read more of his thoughts on the subject at http://azuredba.com/blog.aspx

11 mins, 9 secs

Wednesday, July 8, 2009 12:46:42 PM (GMT Daylight Time, UTC+01:00)
# Thursday, May 28, 2009

Episode 27

In this interview, Microsoft Developer Evangelist Jennifer Marsman describes Windows Azure and tells how to get started developing applications using this platform.

14 mins, 35 secs

Thursday, May 28, 2009 6:36:05 AM (GMT Daylight Time, UTC+01:00)