In this post, I’m going to kick off a series in which I’ll walk through the creation of a back-end service for a Windows 8 app. This first post will provide an overview of the series, and introduce a couple of potential technologies you can use to build your back-end services.
While there are many possibilities in terms of tools you can use to build and host back-end services, I’m going to focus for now on two:
- SQL Azure, Entity Framework, and WCF Data Services, hosted in a Windows Azure web role
- The recently-annouced Windows Azure Mobile Services
I will discuss the capabilities, advantages, and disadvantages of each platform, as well as some of the basics of my solution design. In subsequent posts, I’ll dig deeper into each individual platform, and show how my solution using them can be easily integrated into a couple of games written by my peers.
The games I will be using in my examples were created by two of my fellow technical evangelists, Chris Bowen, and David Isbitski.
Catapult Wars game screen
Catapult Wars is a win or lose game…you are the red catapult, and the game AI is the blue catapult, and you play until one player has no lives left. This allows me to track a leaderboard based on Win/Lose record.
Space Cadet game screen
Space Cadet, as it exists on Codeplex at the time of this writing, is an open-ended game with the action getting faster and faster with each score level, until the player gives up. In order to make the game work for my leaderboard scenario, I’m making some tweaks to introduce a game timer, so players will see how many ships they can destroy within a set time. This allows me to track a leaderboard by high score.
To help focus on the most pertinent aspects of building a back-end service, I’m keeping my data schema pretty simple. Here’s what I’ll be tracking:
- ID – managed by the persistence mechanism, the unique ID for a given record
- Game – name of the game for a given record
- Player – name of the player for a given record
- Score – the high score, if applicable, for a given record
- Wins – the number of wins for a given player/game, if applicable
- Losses – the number of losses for a given player/game, if applicable
- Ties – the number of ties for a given player/game, if applicable
With the above information, we can track either high scores or win/loss/tie records for a variety of players across a variety of games.
Now let’s look at our contenders for the role of back-end service…
SQL Azure, Entity Framework, and WCF Data Services
If your goal is to implement this kind of back-end service right now, a good choice would be to build an OData service on top of an Entity Framework model with a SQL Server back-end. Conveniently, you can do all this in the cloud with SQL Azure and Windows Azure. For this version of the leaderboard service, I’ll be utilizing a SQL Azure database for storing my data, building a model on top of the data with Entity Framework, and exposing that data as an OData service using WCF Data Services. This will make it easy to access the data using simple WinJS.xhr requests (WinJS.xhr is a wrapper around the XmlHttpRequest object that adds support for asynchronous calling via Promises).
Here are the advantages and disadvantages of this stack for my leaderboard service:
- Comparatively mature platform
- Can return data in XML (ATOM-PUB) or JSON format
- Familiar environment for developers used to SQL Server
- Easily create and expose custom logic using .NET code
- More complex to implement than Windows Azure Mobile Services
Windows Azure Mobile Services
Here are the advantages and disadvantages of Windows Azure Mobile Services for my leaderboard service:
- Very simple to use…just create a table, reference the client library, and write my queries
- Also provides push notification and authentication support
- Free during preview period
- Windows Azure Mobile Services is currently a preview release, so it would be wise to wait for the final release to implement in a production app
- Fewer customization points compared to SQL/EF/WCF Data Services stack
- Client can create columns dynamically via code…so typos can get interesting (more on this in a future post)
In this post, I’ve outlined the challenge I’m looking to solve with a back-end service in the cloud, namely hosting a leaderboard for one or more games that I might want to release for Windows 8, or other platforms. I’ve discussed the two games I plan to use to demonstrate the integration of my leaderboard service, and I’ve described the two stacks on which I will implement the leaderboard service.