Top Reasons Developers Should Use Windows Azure Mobile Services

This article is also available on the RedBit Site

With the recent release of Social Cloud, I asked the RedBit team what are the top reasons for using Windows Azure Mobile Services and here is what we have.

Easy Third Party Authentication

Using the Identity feature of Azure Mobile Services allows developers to quick implement OAuth based authentication without having to worry about a lot of the plumbing code that is required when writing everything from scratch.

You can easily incorporate authentication with

  1. Microsoft Account
  2. Facebook
  3. Twitter
  4. Google

As a developer all you would have to do is

  1. Specify the keys in the portal
  2. Use the mobile SDK for iOS, Android, Windows 8, Windows Phone with application
  3. Authenticate via the SDK calling MobileServiceClient.LoginAsync()

Here is what it would look like from the dashboard to setup keysidentity

 

To learn more about this feature see Get Started With Authentication with Mobile Services

Data Storage

Most mobile apps written today need some form of data storage and usually the process is

  1. Figure out where to host it
  2. Figure out what type of database to use
  3. Write some REST APIs to access the data
  4. Make sure the APIs are secured

Using the data feature of Azure Mobile Services developers can quickly create data tables, secure the data tables for read/write operations and also write custom scripts to run when an insert, update, delete or read operation is performed on the data.

From the client side, using the SDK, you call the MobileServiceClient.GetTable<>() method and data will be retrieved.  If the data is secured via the portal settings, you will need to login using the client SDK before attempting to retrieve the data.

For more information see Get Started with Data in Mobile Services.

Client Libraries

Azure Mobile Services comes with clients libraries for the main mobile platforms available in the market today which are

  1. iOS
  2. Android
  3. Windows Phone 8
  4. Windows 8 (C# & JavaScript)
  5. Xamarin for iOS & Android

Leveraging this library and Azure Mobile Services on the back end, developers can focus on writing their app and not all the extra plumbing required for things such as authentication.

Custom APIs

The API feature is relatively new (as of Jun 24 2013) to Azure Mobile Services but allows developers to quick build APIs to the systems to be accessed by various client applications. You can quickly build out the APIs required by your app and just as quickly secure the APIs making sure only authenticated users have access to the APIs. Definitely something to use more often in the future!

Push Notifications

I’m a big fan of push notifications for mobile apps because it allows users to stay connected and engaged with their users. It’s also a great way to entice users to open your apps and this is especially useful if you are monetizing your apps with in app advertising.

Using Azure mobile Services, developers can quickly get this up and running on the various platforms such as iOS, Android, Windows Phone 8 and Windows 8 and it’s as easy as setting a few keys in your Azure Mobile Services Dashboard

push

Definitely something every developer should look at to keep their users engaged with their app.

For more information on how to get this running, see Get Started with Push Notifications in Mobile Services.

Overall, I think Windows Azure Mobile services really helps accelerate the development cycle and get your product to market faster. It allows you to focus on building out your product on not have to worry about server infrastructure or plumbing code required for things like authentication.  When you need to scale, it’s just a few clicks and you are ready to handle your extra load from your users.

So those are our top reasons for using Windows Azure Mobile Services. If you have used it, what are your top reasons? Ping me or the RedBit team on Twitter or leave a comment here.

Monitoring Social Media with Social Cloud

This article is also available on the RedBit Site

Tracking and visualizing social media streams in real-time and across multiple social networks can be a challenge. Three months ago we set out to address this challenge, in partnership with our friends at IdeaNotion and Microsoft.

Today we’re pleased to release as Open Source the Social Cloud project.

social cloud logo-blue

Social Cloud allows users to monitor various social media channels such as Twitter, Instagram and FourSquare, aggregate and process that data (e.g. generate word clouds) and expose real-time streams to web & mobile clients.

The entire solution consists of the following:

  1. NodeJS “emitters” on Linux VMs running concurrently to monitor social media  streams
  2. NodeJS “server” exposing streaming data to front end visualization systems
  3. An admin web dashboard built in NodeJS & Bootstrap
  4. Native iPhone, Android and Windows Phone admin clients built using Xamarin
  5. Email, SMS, push notification & in-app alerts using SendGrid, Twillio & Pusher
  6. HTML5/Canvas visualization engine powered by IdeaCloud

Here is an architectural overview of the system that was built using Windows Azure

architecture

On the outside, seems like a pretty easy concept, but internally there are a lot of components to make this an efficient scalable system. Here is a list and description of all of the features used for the system.

Azure Virtual Machines

Windows Azure has the ability to run Virtual Machines or VMs in the cloud. The ability to spin up a VM in a few minutes is great from a development standpoint because we can spin up test boxes with minimal effort and minimal network infrastructure.

Social Cloud leverages this feature and we utilize Linux VMs to run our NodeJS processes. We went with a Linux VM because of WebSockets support and we needed a little more control than what Azure Websites provided. Also, the development team felt more comfortable with Linux VM instead of Windows and allowed us to easily start multiple NodeJS instances to monitor social media streams.

arch-VMs

As you can see from the diagram, there are multiple NodeJS instances running each monitoring their own social network. In the case of Twitter, we were able to use their streaming API for realtime results while the others are using a polling techninque.  Once we receive the data, we store it in a mongoDB instance and pass a message off to Azure Service Bus for downstream processing.

arch-serviceBus

Windows Azure Service Bus

Social Cloud uses the Windows Azure Service Bus to detach the process of gathering the various social messages from the processing of said messages to ensure that we can receive the messages as quickly as possible.  One of the different processes that subscribe to the Azure Service Bus topics are the Word Emitter that listens for text based messages and splits them into the words, processes them, then places new messages back onto the Bus.  Another subscription listener is the Socket.IO process that passes incoming messages from the bus to each of the listening Socket.IO clients.  This separation also provides the benefit of being able to withstand one component failing, as the messages are queued until the process is brought back online.

arch-serviceBusClients

Windows Azure Websites

Social Cloud leverages Windows Azure Websites to run the administration dashboard which is written using NodeJS. This site also provided APIs to be accessed by iPhone, Android and Windows Phone apps. We leveraged the Git deploy feature available and the integration with BitBucket for automated deployments.

dashboard

arch-websites

Windows Azure Mobile Services

Windows Azure Mobile services are one of the new features that is still currently in preview mode but we still did manage to use some of the features available for the Social Cloud solution.

Some of the features used are

  1. Data – this feature allows you to easily store data within your system from clients accessing the system. Specifically we used it to store device information when implementing push notifications. It also allows you to easily set permissions to read/write the data and also write custom scripts to run when an insert, update, delete or read operation is performed on the data
  2. APIs – APIs is a relatively new feature and essentially allows developers to implement some custom REST APIs required for the system. It also easily allows developers to add support for permissions to any operation performed.
  3. Push – this feature allows developers to create native push notifications to Windows 8, Windows Phone 8, Android and iOS clients. This is great as you can quickly get this infrastructure setup in minutes.
  4. Identity – authenticating users is usually required in mobile apps. Social Cloud required it as we only allowed authorized users to access the data. Using the Identity feature we were able to quickly add authentication to things such as Google, Facebook, Twitter and Microsoft Account.

Essentially, Azure Mobile Services allowed us to quickly implement features such as authentication on mobile clients, and let us build out the features of Social Cloud and not worry about plumbing required for things such as authentication.

arch-mobileServices

Windows Azure Store

For Social Cloud, we leveraged various third party components to add features and functionality to the system. The store allowed us to quickly find and purchase the third party services relatively quickly to be integrated into the Social Cloud system. The following third party components were used in the system

  • MongoLab – store all the streaming data coming in
  • Twillio – send text notifications
  • SendGrid – send email notifications
  • Pusher – send notifications to clients connected on the web dashboard
  • New Relic – monitor the health of the system

arch-store

Social Cloud is a pretty extensive system requiring many different custom components and third party components to produce the required functionality.  Using Windows Azure and the different features available such as Azure Mobile Services, Virtual Machines and Service Bus allowed us to build a robust system quickly and easily.

Over the next few days we’ll be posting some technical blog posts on the system but as of now all the source code is available on GitHub. Be sure to monitor this blog or follow me or the RedBit team on Twitter to get notified when the code is released.

 

Quick Tip: Getting Device ID on Windows & Windows Phone

When building out apps, there are some situations where you are required to get a unique ID of the device whether it be for analytic data or to potentially limit devices from accessing some private services.

This quick tip will show you how to get the device ID on different platforms such as Windows Phone 7, Windows Phone 8 and Windows 8.

Windows Phone 7

To get device ID on Windows Phone 7 you can use the following

private string m_DeviceUniqueId;
public string DeviceId
{
    get
    {
        if (m_DeviceUniqueId == null)
        {
            object val;
            if (Microsoft.Phone.Info.DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out val))
                m_DeviceUniqueId = Convert.ToBase64String((val as byte[]));
        }
        return m_DeviceUniqueId;
    }
}

Windows Phone 8

Getting device ID on Windows Phone 8 is slightly different the the previous version and can be accomplished with the following

private string m_DeviceUniqueId;
public string DeviceId
{
    get
    {
        if (m_DeviceUniqueId == null)
        {
            m_DeviceUniqueId = Windows.Phone.System.Analytics.HostInformation.PublisherHostId;
        }
        return m_DeviceUniqueId;
    }
}

Windows 8

On Windows 8, it’s yet another API to get the device ID and can be accomplished with the following

private string m_DeviceUniqueId;
public string DeviceId
{
    get
    {
        if (m_DeviceUniqueId == null)
        {
            var token = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);
            var hardwareId = token.Id;
            var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);

            byte[] bytes = new byte[hardwareId.Length];
            dataReader.ReadBytes(bytes);

            m_DeviceUniqueId = BitConverter.ToString(bytes).Replace("-","");
        }
        return m_DeviceUniqueId;
    }
}

Gotchas

If you are using this code to get ID with your apps, be aware that the ID returned will be different in every app.  For example, if you have APP1 and APP2, APP1 may return 12345 as the device ID and APP2 may return 09876 as the device ID even though they are running on the same device.

Enjoy!

Sharing Code Part IV: Portable Class Libraries

In the last three posts, I have gone through various ways to share common code across the various Windows based platforms. So far in this series of articles in sharing code we have looked at

  1. Sharing Code Part I: Common Source File (source code download)
  2. Sharing Code Part II: Partial Classes (source code download)
  3. Sharing Code Part III: Conditional Compile (source code download)

In this final part, we’ll look at using a Portable Class Library to share the Math2 class across the different platforms instead of the C# source code file. Personally, I prefer sharing the source code file across the platforms and not sharing an assembly as it gives a little more control. Of course, if I’m building out an API or SDK for external developers to use, a Portable Class Library is the way to go. Continue reading Sharing Code Part IV: Portable Class Libraries

Sharing Code Part III: Conditional Compile

In the first part of Sharing Code series we looked at sharing a common class source file across three different platforms, and in the second part we continued with using partial classes to separate the code out. In this third part of the series, we’ll look at using conditional compiles in our code and continue working on the sample code from the previous articles. Continue reading Sharing Code Part III: Conditional Compile

Sharing Code Part II: Partial Classes

In the first part of Sharing Code series we looked at sharing a common class source file across three different platforms. Continuing the series on Sharing Code across various platforms, we’ll look at leveraging partial classes to help share code across our many apps on Windows 8, Windows Phone 7 & Windows Phone 8 using the same source code from Part I.

What is a Partial Classes?

Essentially a partial class allows you to separate a class or structure into two or more separate files. Personally, I use this technique to hide any specific platform code from other platforms.

Continue reading Sharing Code Part II: Partial Classes

Sharing Code Part I: Common Source Files

In this article, I’ll go through how to share source code files between Windows Phone 8, Windows Phone 7.1 and Windows 8.  In this sample we’ll go through how to share a Math class between two separate Windows Phone projects.

Creating the Projects

First thing is to create two Visual Studio 2012 Projects one for Windows Phone 7.1, 8 and Windows 8.

Windows Phone 7.1 Project

Create a Windows Phone Project and call it WP7_App and uncheck ‘Create Directory for solution’.

Continue reading Sharing Code Part I: Common Source Files

Sharing Code Across Platforms: Introduction

In 2006 I did a presentation on that focused on .NET Compact Framework for Desktop Developers where the core focus was on how to leverage existing code from the full desktop .NET Framework and .NET Compact Framework.

Well seven years later (yes I’ve been doing this a long time!), some of those techniques are still usable with all the different mobile platforms available and as a developer you definitely want to leverage as much code as possible.

In the next series of articles, I will go through some techniques on sharing code across different platforms including Windows Phone 7, Windows Phone 8 and Windows 8. You can use some of the techniques also on iOS and Android using Xamarin.

The following topics will be covered:

  1. Sharing Code Part I: Common Source File (source code download)
  2. Sharing Code Part II: Partial Classes (source code download)
  3. Sharing Code Part III: Conditional Compile (source code download)
  4. Sharing Code Part IV: Portable Class Libraries (source code download)

I have personally used these techniques with various products we have built plus customer work.  By the end of the series, hopefully you will have a good understanding on how to leverage your code across different platforms using C#.

Note that the samples being used are not using anything like MVVM or other frameworks as it’s something I was using my 11yr old son on using programming to solve some math homework he had and I wanted to keep it as simple as possible.

Windows Phone & HTML5 Sample App Summary

I recently wrote a four part article about how to build a simple count down timer app using HTML5 and Windows Phone.  The articles covered getting started with HTML5 and Windows Phone, multiple resolutions, using the WebBrowser control to ‘talk’ to web page and finally getting ready for Windows Phone Store certification.

Here is the result of the articles.

finalImage

Here is a list of the articles available for easy reference

  1. XBoxReveal HTML5 Windows Phone Sample
  2. XBoxReveal HTML5 Windows Phone Sample: Multiple Resolutions
  3. XBoxReveal HTML5 Windows Phone Sample: WebBrowser Control
  4. XBoxReveal HTML5 Windows Phone Sample: Store Certification

As for the source code, if you want to run it yourself you can download the #xboxreveal source code from GitHub.

Hope it was useful and please leave comments or questions!

XBoxReveal HTML5 Windows Phone Sample: Store Certification

In this final article of the XBoxReveal HTML5 Windows Phone sample, I’ll be going through some of the things you need to do as a developer to get ready for Windows Store Certification.

If you have not read the previous articles, here is a list for some background

  1. XBoxReveal HTML5 Windows Phone Sample
  2. XBoxReveal HTML5 Windows Phone Sample: Multiple Resolutions
  3. XBoxReveal HTML5 Windows Phone Sample: WebBrowser Control

Getting Ready for Store

The first thing you want to do to get ready for Windows Phone Store certification is read the App Certification Requirements for Windows Phone article on MSDN.  Lucky for the people who don’t like going through the entire document (like me 🙂 the Windows Phone SDK comes with a Store Test Kit to help go through the cert process.

wp-testkit

Continue reading XBoxReveal HTML5 Windows Phone Sample: Store Certification