Mobile Services

Silicon Valley Code Camp 2013 – Windows Azure Mobile Services

Svcc

The Silicon Valley Code Camp is the biggest free conference of the Silicon Valley. On October 5th and 6th, come to learn about any technology (not only Microsoft) at the Foothill College in Los Altos Hills, CA. And this year, I have the change to speak with Eugene Chuvyrov (@EugeneChuvyrov) about Windows Azure Mobile Services. We will show you how to integrate Azure Mobile Services in your existing applications running iOS and Windows Phone.

Fast & Furious iOS and Windows Phone development with Azure Mobile Services

Time to market is critical in mobile application development, and new cloud-based technologies are here to help you get your apps out the door faster. By abstracting back-end operations and using a powerful SDK, Windows Azure Mobile Services allows you to focus on creating beautiful native User Interfaces on the web (HTML 5), iOS, Android, Windows Phone and Windows 8 devices and coding custom logic for these platforms. In this presentation, Eugene Chuvyrov and Fabien Lavocat will demonstrate how a single backend hosted on Windows Azure Mobile Services powers both iOS and Windows Phone devices. Taking advantage of the data from Dun & Bradstreet Developer Challenge, they will demonstrate a mobile CRM system that they created for these platforms.

I am speaking at silicon valley code camp. Please come to my session!  Click here for details.

Send a web request to a Web Site periodically using Azure Mobile Services

Mobile Services

Today I’m facing a new challenge with IIS (Internet Information Service) of one of my Web Site on Windows Azure. As you probably know, after a few minutes of inactivity, IIS will go take a nap and will wake up at the next incoming request. It means after about 15 – 20 minutes, if your web site did not receive any incoming request it will pause itself. And the following request will take longer because the web server needs to start. It can be a problem for the guests visiting your web site or consuming your services. One solution is to use Windows Azure Mobile Services and more precisely the Scheduler feature.

Just to remind you, Azure Mobile Services is free, up to 10 services, using shared instances. So let’s use it!

Continue reading

Global Windows Azure Bootcamp – Mobile Services for Earthquakes

GWAB Mobile Services

Saturday April 27th, 2013 was the day of the Global Windows Azure Bootcamp (GWAB). With more than 90 locations all around the world, GWAB was THE world-wide event about Windows Azure. Thanks to @RobinDotNet I had the chance to give a 15 minute presentation on how I use Windows Azure Mobile Services in my application Earthquakes for Windows Phone. Today I’m going to share with you, on this blog, my presentation and at the same time, add some details and answer some questions I received after the talk.

Continue reading

Azure Mobile Services – Paging with REST APIs

Mobile Services
I would like to complete the code I’ve provided to call the REST APIs for Windows Azure Mobile Services in my two previous posts, Introduction to Windows Azure Mobile Services and Windows Azure Mobile Services – Update with REST APIs. Today, I’ve been facing a basic mistake I made for my application Earthquakes. You are more and more everyday to use this application, and I thank you for that :). Each time a new user start the application, the app will register on Azure Mobile Services in order to update the Live Tile on the Phone (see the picture below). It means I store a list of URLs on Mobile Services, and I’ll contact these URLs to update the Live Tile on your phone.

Earthquakes Live Tiles
If you’ve read and use the source code I’ve provided you’ve probably noticed an issue. How do you retrieve a list of more than 50 entries in Mobile Services? You have two possibilities:

  • The first idea would be to increase the number of items you want to retrieve when you call the REST API. In order to do that you have to specify the parameter $top of the REST API. You can ask up to 1000 items in one call. But what’s going on if you have more than a thousand items in your base? You’ll simply never get them and it’s what happened to me. I was stuck with the 50 firsts items…
    URL format: https://<ServiceName>.azure-mobile.net/tables/<TableName>?$top=<Limit>
  • The other idea and probably the better in most of the cases, is to use paging. The paging capability allows you to retrieve your elements by lot, 50 at a time for example, until you have all of them. To do so, we will combine the attributes $top and $skip. Also, by using the attribute $inlinecount with the value allpages we will get the number of elements in the table at each call. It will help us to track if we need to perform more call to get more elements.
    URL format: https://<ServiceName>.azure-mobile.net/tables/<TableName>?$top=<Limit>&$skip<Skip>&$inlinecount=allpages

Let’s start coding with a class named RestResult that we will use to deserialize the elements including the number of elements in the table.

[DataContract]
public sealed class RestResult<T>
    where T : class
{
    [DataMember(Name = "results")]
    public T[] Results { get; set; }

    [DataMember(Name = "count")]
    public int Count { get; set; }
}

Now, we can update the function Get to retrieve an object RestResult<T> that will contain the list of elements we asked and the number of elements in the table.

public RestResult<T> Get<T>(string tableName, string filter = "", int skip = 0, int top = 50)
    where T : class
{
    if (!string.IsNullOrWhiteSpace(filter))
        filter = string.Concat("&$filter=", filter);

    Uri address = new Uri(string.Format("https://{0}.azure-mobile.net/tables/{1}?$inlinecount=allpages&$skip={2}&$top={3}{4}",
                                        ServiceName, tableName, skip, top, filter));

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);

    request.Method = "GET";
    request.Headers = new WebHeaderCollection
                            {
                                {"X-ZUMO-APPLICATION", ApplicationId},
                                {"X-ZUMO-MASTER", MasterKey},
                            };

    RestResult<T> result;

    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
    {
        Stream stream = response.GetResponseStream();

        result = stream.Deserialize<RestResult<T>>();
    }

    return result;
}

And to finish, here is the code that will retrieve all the elements of a table.

public IEnumerable<T> GetAll<T>(string tableName, string filter = "")
    where T : class
{
    List<T> result = new List<T>();
    bool needMore;

    do
    {
        var get = Get<T>(tableName, filter, result.Count);
        result.AddRange(get.Results);

        needMore = get.Count > result.Count;
    } while (needMore);

    return result;
}

Monitoring the Cloud Services, Websites, Mobile Services and Virtual Machines

MonitorEndPoints

Windows Azure is evolving very fast. I don’t remember seen a Microsoft moving that fast. Scott Guthrie introduced a bunch of new features on his blog yesterday. Today, I’m going to focus only on the new capability to monitor an endpoint. Available for your Cloud Services, Websites, Mobile Services and Virtual Machines, you’ll able to understand how fast (or slow) are your services for your customers around the world.

Beware that the feature works only in Reserved Mode. So if you want to track your Websites or Mobile Services do not forget to switch them to Reserved Mode in the SCALE panel.

OnlyReservedMode

You can add up to two endpoints to monitor for each service and each endpoint can be monitored from 3 different locations from the following list.

  • Chicago, IL, USA
  • San Antonio, TX, USA
  • San Jose, CA, USA
  • Ashburn, VA, USA
  • Dublin, Ireland
  • Amsterdam, Netherland
  • Hong Kong
  • Singapore

Each location for each endpoint will bring you two more metrics to monitor in the MONITOR panel:
Select Metrics
I don’t have enough information on my own Virtual Machines so I’m using the picture posted by Scott Guthrie on his blog:
Result Monitoring

Windows Azure Mobile Services – Update with REST APIs

Windows Azure Mobile Services

After the introduction to Windows Azure Mobile Services, I hope you had the chance to try this service. Di you know you can try Windows Azure for free for 90 days?

Today I would like to add a very short code snippet to help you updating an item in your Mobile Service. We have to use the HTTP method PATCH, send the id of the item to update and send the new item in the body of your request (serialized as a JSON message). You can use the following method in the class I gave to you in my introduction to Windows Azure Mobile Services.

public void Update<T>(string tableName, int idToUpdate, T item)
    where T : class
{
    Uri address = new Uri(string.Format("https://{0}.azure-mobile.net/tables/{1}/{2}", ServiceName, tableName, idToUpdate));

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);

    request.Method = "PATCH";
    request.Headers = new WebHeaderCollection
                            {
                                {"X-ZUMO-APPLICATION", ApplicationId},
                                {"X-ZUMO-MASTER", MasterKey},
                            };

    string serialization = item.Serialize();
    byte[] byteData = Encoding.UTF8.GetBytes(serialization);
    request.ContentLength = byteData.Length;

    using (Stream postStream = request.GetRequestStream())
    {
        postStream.Write(byteData, 0, byteData.Length);
    }

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    response.Close();
}

Introduction to Windows Azure Mobile Services

MobileServices

Today I would like to write about one of the feature on Windows Azure that was created by the team of Scott Guthrie. This new service, still tagged as a preview in the Azure management console, allows you to make easier your developments for Windows Phone, Windows 8 and even iPhone and Android devices with:

  • Structured storage. You can send and retrieve structured data between your client device and Azure using JSON messages or with the Windows Azure Mobile Services SDK. The backend of this storage is a SQL Server database but you don’t have to take care of it. Windows Store C#, Windows Phone 8, iOS.
  • User authentication. You will be able using a very simple line of code to get your mobile users to authenticate using for example their Microsoft Account or Facebook to access some restricted data or just to be identify by your system. Windows Store C#, Windows Phone 8, iOS.
  • Push notifications. Send a push notification to display a toast or change the tile on the client device has never been easier. With one line of JavaScript embedded on Azure, you can send push notification to all of your users. Windows Store C#, Windows Phone 8, iOS.

Microsoft did an amazing job by creating a lot of content to help developers creating applications using Windows Azure and I’ve linked, for each feature mentioned above, the corresponding tutorial for Windows 8 and Windows Phone 8 apps or even iOS.

Ok, now that we have the big picture of what is Windows Azure Mobile Services, let’s code a little bit. For one of my project I’m working on, I needed to connect Mobile Services, not from a mobile device but from a Worker Role also hosted on Azure. The main problem is that the Mobile Service SDK is not working for other projects than Windows 8, Windows Phone 8 (in the .NET world). Remember what I said about the Structured storage? You can exchange data using JSON messages. So I’ll use the REST APIs to communicate with my backend.

Continue reading