Click here to close now.


Microservices Expo Authors: Elizabeth White, Don MacVittie, Liz McMillan, Pat Romanski, Carmen Gonzalez

Related Topics: @CloudExpo, Mobile IoT, Microservices Expo, Microsoft Cloud, Silverlight, Apache

@CloudExpo: Article

Windows Azure Mobile Services

Windows Azure Mobile Services is the bomb, but how can we work with enum values?

Now, in order to do this, it makes some assumptions.  It looks at the JSON object, and if it sees a certain type of data, it creates a certain type of column to support the data.  The easiest thing that it could have done would be to just create text columns in the underlying SQL database, since any type of data can be stored as a string.  Instead, it does something quite a bit smarter, and creates data types that are quite a bit more “appropriate”.  Here’s the strategy that it uses:

JSON / CLR Data Type T-SQL Type in underlying SQL Azure database table
Numeric values (integer, decimal, floating point) float(53) – this is the maximum precision float.
Boolean bit
DateTime DateTimeOffset(3)
String nvarchar(max)

OK, so this is great.  Dynamic schema is pretty cool.  However…

When I work on a database schema, I often run into a case where I want to create a “code/decode” style table.  In my world, a “code/decode” table is typically a two column table, where the primary key is the “code” and the other column is a textual description.  The canonical example is a “States” table (in the US).  Like this:

Code Decode
AL Alabama
AK Alaska
AZ Arizona
IL Illinois
WY Wyoming

Then, with this table defined, I’ll just use it anywhere I need a State… like this:

Column DataType Notes
FirstName nvarchar(50)
LastName nvarchar(50)
Address1 nvarchar(100)
Address2 nvarchar(100)
City nvarchar(100)
State char(2) Foreign Key to State Code
ZIPCode char(5)

Now, in my current project, it wasn’t a state code that I needed, it was a “CurrencyType”.  And moreover, I wanted to be able to have an “enum” value of CurrencyTypes to be able to work with in my application.  This led me to wonder how WAMS could handle storing and retrieving an “enum” in the database.  It’s not immediately clear that it would know what to do with it as a JSON type.  The JavaScriptSerializer seems to turn enum values into an integer value, which would probably work, but I really wanted my underlying SQL table to store “IL” for Illinois, and not the number 14 as a 53 bits of precision float.  So, how can I turn my enum values into the underlying state codes as a 2 character string on the way in, and reconvert them back to my enum values on the way out?

To start with, here’s the (truncated) version of my enum for my CurrencyType.

public enum CurrencyType

Next, the secret sauce turns out to be an IDataMemberJsonConverter .  This interface exists within the Microsoft.WindowsAzure.MobileServices assembly, and has 2 methods that you need to implement – ConvertFromJson and ConvertToJson.  Here’s the type converter that I created to massage my enum into a string going in, and from a string back to the enum on the way back out…

First, the ConvertToJson method:

public IJsonValue ConvertToJson(object instance)
	if (instance is Types.CurrencyType)
		switch ((Types.CurrencyType)instance)
			case Types.CurrencyType.UnitedArabEmiratesDirham:
				return JsonValue.CreateStringValue("AED");
			case Types.CurrencyType.AfghanistanAfghani:
				return JsonValue.CreateStringValue("AFN");
			case Types.CurrencyType.AlbaniaLek:
				return JsonValue.CreateStringValue("ALL");
			case Types.CurrencyType.UnitedStatesDollar:
				return JsonValue.CreateStringValue("USD");
				return JsonValue.CreateStringValue("XXX");
		return JsonValue.Parse("null");

Next, the ConvertFromJson method:

public object ConvertFromJson(IJsonValue value)
	CurrencyType result = Types.CurrencyType.Unknown; 
	if (value != null && value.ValueType == JsonValueType.String) 
		switch (value.GetString()) 
			case "AED": 
				return Types.CurrencyType.UnitedArabEmiratesDirham; 
			case "AFN": 
				return Types.CurrencyType.AfghanistanAfghani; 
			case "ALL": 
				return Types.CurrencyType.AlbaniaLek;
// SNIP 
			case "USD": 
				return Types.CurrencyType.UnitedStatesDollar;
// SNIP 
			case "ZWD": 
				return Types.CurrencyType.ZimbabweDollar; 
			case "XXX": 
				return Types.CurrencyType.Unknown; 
				return Types.CurrencyType.Unknown; 
	return result;

Now, the only thing remaining is to decorate the CLR class that we’re using to hold our object with enough information to get the serializer to use our type converter as necessary.  In my case, the column for CurrencyType is contained in a class called FamilyGroup.  Here’s that implementation:

public class FamilyGroup
	public long Id { get; set; } 
	public string Name { get; set; }

 	[DataMemberJsonConverter(ConverterType = typeof(CurrencyTypeConverter))] 
	public CurrencyType CurrencyType { get; set; }

And that’s it.  We have our enum to work with in our code, we’re able to store and retrieve our values to WAMS and the data in the tables is readable to boot.

Happy coding.

More Stories By Adam Hoffman

Adam is an technical evangelist working for Microsoft. By day, you can likely find him somewhere in the Midwest, driving to somewhere, ready to figure out how the cloud can save your family from certain doom, and make you rich and successful in the process. Before he started evangelizing, Adam was a Senior Developer Lead for Microsoft in Redmond, working on Office 365, BPOS, and Office Live. He misses Redmond, and the excitement of the mother ship, but the call of bitter cold and lots of snow in Chicago was too much for him, and he had to return.

Prior that that he developed software and ran teams for Thomson Reuters, Method Engine (which he co-founded), VSA Partners, Navigant Consulting, Andersen Consulting, and a couple of CASE tool companies way back in the day. His favorite possession is a clone of the original Altair computer, running BillG's 8K BASIC, which he's still intending to hook up to the cloud, someday, somehow.

You can read his Windows Azure Blog at, and tweeter-er him at

Additionally, if you'd like to keep track of his cloud connected car, you can follow it on Twitter at

@MicroservicesExpo Stories
As operational failure becomes more acceptable to discuss within the software industry, the necessity for holding constructive, actionable postmortems increases. But most of what we know about postmortems from "pop culture" isn't actually relevant for the software systems we work on and within. In his session at DevOps Summit, J. Paul Reed will look at postmortem pitfalls, techniques, and tools you'll be able to take back to your own environment so they will be able to lay the foundations for h...
Now, with more hardware! September 21, 2015, Don MacVittie, Sr. Solutions Architect. The “continuous” trend is continuing (get it..?), and we’ll soon reach the peek of the hype cycle, with continuous everything. At the pinnacle of the hype cycle, do not be surprised to see DDOS attacks re-branded as “continuous penetration testing!” and a fee … Read More Continuous Provisioning
Containers are revolutionizing the way we deploy and maintain our infrastructures, but monitoring and troubleshooting in a containerized environment can still be painful and impractical. Understanding even basic resource usage is difficult - let alone tracking network connections or malicious activity. In his session at DevOps Summit, Gianluca Borello, Sr. Software Engineer at Sysdig, will cover the current state of the art for container monitoring and visibility, including pros / cons and li...
SYS-CON Events announced today that Super Micro Computer, Inc., a global leader in high-performance, high-efficiency server, storage technology and green computing, will exhibit at the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. Supermicro (NASDAQ: SMCI), the leading innovator in high-performance, high-efficiency server technology is a premier provider of advanced server Building Block Solutions® for Data ...
Containers are all the rage among developers and web companies, but they also represent two very substantial benefits to larger organizations. First, they have the potential to dramatically accelerate the application lifecycle from software builds and testing to deployment and upgrades. Second they represent the first truly hybrid-approach to consuming infrastructure, allowing organizations to run the same workloads on any cloud, virtual machine or physical server. Together, they represent a ver...
SYS-CON Events announced today the Containers & Microservices Bootcamp, being held November 3-4, 2015, in conjunction with 17th Cloud Expo, @ThingsExpo, and @DevOpsSummit at the Santa Clara Convention Center in Santa Clara, CA. This is your chance to get started with the latest technology in the industry. Combined with real-world scenarios and use cases, the Containers and Microservices Bootcamp, led by Janakiram MSV, a Microsoft Regional Director, will include presentations as well as hands-on...
In a report titled “Forecast Analysis: Enterprise Application Software, Worldwide, 2Q15 Update,” Gartner analysts highlighted the increasing trend of application modernization among enterprises. According to a recent survey, 45% of respondents stated that modernization of installed on-premises core enterprise applications is one of the top five priorities. Gartner also predicted that by 2020, 75% of
Opinions on how best to package and deliver applications are legion and, like many other aspects of the software world, are subject to recurring trend cycles. On the server-side, the current favorite is container delivery: a “full stack” approach in which your application and everything it needs to run are specified in a container definition. That definition is then “compiled” down to a container image and deployed by retrieving the image and passing it to a container runtime to create a running...
Despite all the talk about public cloud services and DevOps, you would think the move to cloud for enterprises is clear and simple. But in a survey of almost 1,600 IT decision makers across the USA and Europe, the state of the cloud in enterprise today is still fraught with considerable frustration. The business case for apps in the real world cloud is hybrid, bimodal, multi-platform, and difficult. Download this report commissioned by NTT Communications to see the insightful findings – registra...
SYS-CON Events announced today that Dyn, the worldwide leader in Internet Performance, will exhibit at SYS-CON's 17th International Cloud Expo®, which will take place on November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. Dyn is a cloud-based Internet Performance company. Dyn helps companies monitor, control, and optimize online infrastructure for an exceptional end-user experience. Through a world-class network and unrivaled, objective intelligence into Internet condit...
Saviynt Inc. has announced the availability of the next release of Saviynt for AWS. The comprehensive security and compliance solution provides a Command-and-Control center to gain visibility into risks in AWS, enforce real-time protection of critical workloads as well as data and automate access life-cycle governance. The solution enables AWS customers to meet their compliance mandates such as ITAR, SOX, PCI, etc. by including an extensive risk and controls library to detect known threats and b...
Our guest on the podcast this week is Jason Bloomberg, President at Intellyx. When we build services we want them to be lightweight, stateless and scalable while doing one thing really well. In today's cloud world, we're revisiting what to takes to make a good service in the first place. Listen in to learn why following "the book" doesn't necessarily mean that you're solving key business problems.
DevOps Summit, taking place at the Santa Clara Convention Center in Santa Clara, CA, and Javits Center in New York City, is co-located with 17th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait...
Overgrown applications have given way to modular applications, driven by the need to break larger problems into smaller problems. Similarly large monolithic development processes have been forced to be broken into smaller agile development cycles. Looking at trends in software development, microservices architectures meet the same demands. Additional benefits of microservices architectures are compartmentalization and a limited impact of service failure versus a complete software malfunction....
The last decade was about virtual machines, but the next one is about containers. Containers enable a service to run on any host at any time. Traditional tools are starting to show cracks because they were not designed for this level of application portability. Now is the time to look at new ways to deploy and manage applications at scale. In his session at @DevOpsSummit, Brian “Redbeard” Harrington, a principal architect at CoreOS, will examine how CoreOS helps teams run in production. Attende...
For it to be SOA – let alone SOA done right – we need to pin down just what "SOA done wrong" might be. First-generation SOA with Web Services and ESBs, perhaps? But then there's second-generation, REST-based SOA. More lightweight and cloud-friendly, but many REST-based SOA practices predate the microservices wave. Today, microservices and containers go hand in hand – only the details of "container-oriented architecture" are largely on the drawing board – and are not likely to look much like S...
DevOps has often been described in terms of CAMS: Culture, Automation, Measuring, Sharing. While we’ve seen a lot of focus on the “A” and even on the “M”, there are very few examples of why the “C" is equally important in the DevOps equation. In her session at @DevOps Summit, Lori MacVittie, of F5 Networks, will explore HTTP/1 and HTTP/2 along with Microservices to illustrate why a collaborative culture between Dev, Ops, and the Network is critical to ensuring success.
With major technology companies and startups seriously embracing IoT strategies, now is the perfect time to attend @ThingsExpo in Silicon Valley. Learn what is going on, contribute to the discussions, and ensure that your enterprise is as "IoT-Ready" as it can be! Internet of @ThingsExpo, taking place Nov 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 17th Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading in...
Containers have changed the mind of IT in DevOps. They enable developers to work with dev, test, stage and production environments identically. Containers provide the right abstraction for microservices and many cloud platforms have integrated them into deployment pipelines. DevOps and Containers together help companies to achieve their business goals faster and more effectively.
Docker is hot. However, as Docker container use spreads into more mature production pipelines, there can be issues about control of Docker images to ensure they are production-ready. Is a promotion-based model appropriate to control and track the flow of Docker images from development to production? In his session at DevOps Summit, Fred Simon, Co-founder and Chief Architect of JFrog, will demonstrate how to implement a promotion model for Docker images using a binary repository, and then show h...