Toronto Code Camp Collateral

I just finished my two presentations at this year’s Toronto Code Camp. As is my standard, I have put my slides on They can be found at:

OData -

Silverlight 4 Out of Browser -

As well, the sample code for the Silverlight 4 talk can be downloaded here.

Silverlight 4 Out-of-Brower Demo Code

This is the demo code for my Silverlight 4 Out of Browser talk at the Toronto Code Camp

Visual Studio 2010 At the Movies

Yesterday was the third (or fourth) annual ObjectSharp At The Movies event., For this particular version, we were able to celebrate the launch of Visual Studio 2010 and .NET 4.0 with a plethora of sessions covering VS (naturally) to ASP.NET, Silverlight, Sharepoint and TFS. All in all, it was a successful day that seemed to give the attendees what they came for. The slides that I used for my portion of the talk (which was an overview of VS2010 and .NET 4) can be found here. As always, feel free to ask questions. And, for those that missed it, we plan on doing it again next year. Just don’t know (yet) what the theme will be.

MIX 10 – First Impressions

Once of the interesting elements of this year’s MIX is the complete domination of Twitter as a medium for distributing updates. If you have been following me on Twitter (I’m @LACanuck), then you will already have heard a lot about the Windows Phone 7 development announcements. However, as useful as Twitter is, it’s not really a place for opinion. Unless your opinions fit into <140 characters. Mine don’t

Windows Phone

There is no question that there is a lot of buzz around developing apps for the Windows Phone 7. This is completely understandable, as WP7 allows Silverlight developers the ability to create applications for the phone. According to Scott Gu’s keynote, there is only “one Silverlight”. That is to say that applications that run on the browser should also be able to run on WP7.

Now there is going to be a little bit of a reality check for that statement, especially as we hit Silverlight 4. I’m not sure, for example, if Silverlight as running on WP7 has the concept of a trusted application. I suspect that it doesn’t, although I’m open to correction if my assumption is misplaced.

But working solely within the security sandbox is not the only real difference. Specifically, the design of a WP7 application is very different than a Web application. The size of the design surface is, naturally, much smaller on the WP7. And the UI needs to consider that main UI gesture is touching, a paradigm that doesn’t apply to Web applications. All of this is to say that while, theoretically, the same application could run on both platforms, it’s much more likely that different views will be used by the different targets. If nothing else screams that you should be using MVVM as a design pattern for Silverlight, this will.


Once you see what’s possible in the WP7 environment, the excitement regarding creating applications is easy to understand. And not only are the apps exciting, so too is the ability to monetize your application. Microsoft will be making a Marketplace available so that you can sell your apps on-line. Given how well Microsoft has done with community driven marketplaces, I have no doubt this will be successful.

But what about your own personal applications? What if you want to develop a WP7 application that is used by your mobile sales force? At the moment, the answer seems to be that you’re out of luck. This might change before it goes live, but the word that I’m hearing is that the only way to get apps onto your phone is through the Marketplace.

Now, that’s not completely accurate. If you have Visual Studio 2010, you can deploy your application to a physically connected phone. However, the time to live for applications which have been deployed in such a matter is limited, To, approximately, a month. After which the app would need to be redeployed.

I’m not a fan of this. In fact, in my mind ,it drops the collection of Silverlight developers who might write WP7 apps by 50%. At least. I can take guesses at the reason why this limitation is the case, but still, it’s not what I was hoping for. The term for what I’m looking for is ‘siloed’ deployment’ (that is, deployment only for people in a particular silo) and I’m hoping that it becomes part of the released version of WP7 before it goes live with the first version.

While there is more of interest that is being revealed here, this is probably a decent start. And I’ll be both blogging and tweeting as much as I can while I’m here at MIX ‘10

Migrating ASP.NET to Azure Sample Web Site

The starting point for the Migrating ASP.NET to Azure article.

The Benefits of Windows Azure

The age of cloud computing is fast approaching. Or at least that's what the numerous vendors of cloud computing would have you believe. The challenge that you (and all developers) face is to determine just what cloud computing is and how you should take advantage of it. Not to mention whether you even should take advantage of it.

While there is little agreement on exactly what constitutes 'cloud computing', there is a consensus that the technology is a paradigm shift for developers. And like pretty much every paradigm shift there is going to be some hype involved. People will recommend moving immediately to the technology en masse. People will suggest that cloud computing has the ability to solve all that is wrong with your Web site. Not surprisingly, neither of these statements is true.

And, as with many other paradigm shifts, the reality is less impactful and slower to arrive than the hype would have you believe. So before you start down this supposedly obvious ‘path to the future of computing’, it's important to have a good sense of what the gains will be. Let's consider some of the benefits that cloud computing offers.

Instant Scalability

If you are tasked with building a customer-facing Web site, then one of the main concerns is scalability. Regardless of the type of site being created, there will be considerable intellectual energy spent determining how to configure the Web servers to maximize the up-time. And in many cases the infrastructure design must also consider issues not related solely to reliability. The ability to handle peak times, which can be a large multiple of the normal level of activity, must also be designed into the architecture.

These spikes in usage come in a couple of different varieties. Sometimes, the spikes come at predictable times. Think of the holiday season for a retail site or a price sale for a travel site. Sometimes the spikes cannot be predetermined, such as a breaking news event for a current events site. But regardless of the type of spikes, the infrastructure architect must create an infrastructure that is capable of absorbing these variations in stride. The result, especially if the peak is 10 times or higher than the average load, is that extra (and mostly unused) capacity must be built into the design. Capacity that must be paid for, yet remains idle.

Into this picture comes cloud computing. Regardless of the cloud platform for which you develop, the ability to scale up and down with the click of a mouse is readily available. For Windows Azure, there are a number of different scalability points, including the number of virtual machines assigned to the application, the number of CPUs in each of the virtual machines, and so on. Within the application itself, you as the designer would have already partitioned the application into the various roles that are then deployed onto the virtual machines.

As the demand on the Web site increases, additional machines, CPUs or roles can be added to ensure a consistency of responsiveness through all of the loads. More importantly, when demand decreases, the resources can be removed. Since these settings form the basis for price paid for the cloud computing service, companies will end up paying only for the capacity that they require.

The price to be paid for this flexibility is that mostly that the application needs to be designed with the necessary roles in mind. As well, there are other constructs (such as the AppFabric and the ServiceBus) and technologies (such as WCF) that need to be mastered and integrated into the application. As a result, it is easier to build a Web application that works with Windows Azure right from the start. This is not to say that existing Web applications can’t be refactored to take advantage of the cloud…they certainly can. But starting from scratch allows you to take full advantage of the benefits offered by Azure.

Expandable Storage

The ability to avoid idle resources is not the only appeal of cloud computing. Another resource that can be virtualized for most applications is the database. Just like the CPU, database usage can rise and fall with the whims and patterns of the user base. And the fact is that the vast majority of business databases do little more that grow in size as time goes one. Again, infrastructure architects need to consider both growth rate and usage patterns as they allocate resources to the database servers. As with the machine-level resources, over-capacity must be designed into the architecture. By using a database hosted in the cloud, the allocation of disk space and processing power can be modified on an as-needed basis. And you, as the consumer, pay only for the space and power that you use.

There are some additional thoughts that need to be given to the use of a cloud database. In order to provide the described flexibility, cloud database providers freely move data from one server to another. As a result, there must be a fairly high level of trust in the provider, particularly if the data is sensitive in nature. For the traditional non-cloud database, the owner of the Web site maintains physical control over the data (by virtue of their physical control over the database servers). Even if the server is hosted at a co-location facility, the Web site owner ‘knows’ where the data is at all times.

When the data is persisted to the cloud, however, this is no longer the case. Now the data is physically in control of the cloud provider. The owner has no idea on which server the data is stored. Or even, when you get right down to it, which city. For some companies, this is a level of trust well beyond what they might have been comfortable with in the past.

As a person who lives abroad, (I’m from Canada), there is one more consideration: privacy. Data privacy laws vary from country to country. When data is stored ‘in the cloud’, there is little weight given to the physical location of the data. After all, the actual location has been virtualized out through the cloud concept. Information can (and does) move across national boundaries based on the requirements of the application. And when data resides in another country, it may very well be subject to the privacy laws of that country. If those laws are significantly different than your own, you might need to modify your corporate policies or the Web application itself to address whichever requirements are more stringent. This sort of situation brings rise to a common approach to cloud storage – data segregation.

In data segregation, the data required by the Web application is stored in multiple locations. Data that is static and/or not particularly sensitive is stored in the cloud. Data that is sensitive is stored in a traditional (and more subject to owner control) location. Naturally, the Web application needs to be structured to combine the data from the different sources. And the traditionally located data needs to be stored in an infrastructure that is reliable and scalable…with all of the problems that the implementation of those features entail.

The functionality offered by cloud computing will be enticing to some, but definitely not all, Web sites. For those who fit the target audience (Web sites that have a wide fluctuation in usage patterns) or just those who want to outsource their Internet infrastructure, cloud computing is definitely appealing. For developers of these sites, platforms such as Windows Azure represents a significant change in the necessary development techniques. And even with the inherent complexity, the shift to cloud computing is beneficial to developers (the resulting applications tend to be more modular, composable and testable), enough to make further exploration of the details worthwhile.

Order Fixation

One of my current tasks for a client has been to facilitate the integration between a Java client and a WCF service. The mechanism for doing this is JSON and I have been quite grateful that WCF makes it relatively easy to implement this type of communication. However, there is one area that has been causing some grief for me (and my Java colleagues) that I finally create a workaround for yesterday.

The source of my problem starts with the contract used by the WCF service. A number of the methods include parameters that are abstract data types. Consider the following class declaration.


public abstract class AbstractCommand

The AbstractCommand class is just a base class for a couple of concrete classes (ButtonCommand and MouseCommand). The WCF method is declared as accepting an AbstractCommand type, but the value passed into the method will be either a ButtonCommand or a MouseCommand.

   RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
StatusCode ExecuteCommand(AbstractCommand command);

Naturally, when the client invokes this method, the expectation is that a concrete class instance will be passed along. However, if all you do is pass in the JSON for one of the concrete classes in, you get an exception saying that an abstract class cannot be instantiate. The reason for the error can be found in how WCF dispatches message. When the request arrives, WCF examines the message to determine which method is to be invoked. Once identified, the parameters for the method (found in the JSON) are created. This creation involves instantiating an object using the default parameterless constructor for the type and then assigning property values as found in the JSON. However, the AbstractCommand type cannot be instantiated (it is abstract, after all). And there is no immediately apparent mechanism to determine which concrete type should be used.

To address this final problem, Microsoft introduced the idea of a type hint. The JSON for a concrete type passed into the ExecuteCommand method would look something like the following:

{"command":{"__type":"ButtonCommand:#Command.Library", "prop1":"value", "prop2":"value"}}

The name/value pair of “__type” is used by WCF to determine the type that should be instantiated before performing the property assignment. This is conceptually similar to how types are provided through SOAP. This mechanism does have the hard requirement that the “__type” value be the first pair in the JSON list.

Enter Java into the picture. In order to communicate with my WCF service, the client using the Java JSONObject class. This class takes a collection of name/value pairs and converts it into a JSON-formatted array. This array is then sent to my method, where it goes through the previously described process. However the JSONObject seems to take the portion of the JSON specification where it says the name/value pairs are ‘unordered’ to heart. There is (apparently) no way to force a particular name/value pair to be emitted as the first pair. In other words, the JSONObject cannot reliably produce JSON for a concrete type that is being passed into a parameter of an abstract type.


Well, it was actually stronger language than that once I figured this out.

The solution was not nearly as complicated as identifying the problem. I created a WCF endpoint behavior extension. In the AfterReceiveRequest event handler, I look at the body of the request (which has already been converted into XML, as it turns out..a surprise, albeit an easier choice format for the next step). If the “__type” property is the first pair in the JSON array, it is converted to a “__type” attribute in the XML element. Otherwise, it appears as a regular child node. So the transformation consists of finding the XML elements that have a name of “__type” and moving the value up into an attribute of the parent node. The modified message is then injected back into the WCF pipeline. And now the request is processed as desired.

Setting the Default Style for a Custom Silverlight Control

Like so many of my posts, this one is as much about keeping a log of what I learned. And, in this particular case, since I had a difficult time finding the answer (and the answer is relatively new), a blog posts is doubly worthwhile.

I was trying to write a custom control for Silverlight 3. It was an extension to a ListBox, so I created a class that derived from ListBox and added my neat-o cool functionality. However, part of the requirements for the control was (for example) that it needed to be horizontal and that the scroll bars needed to be hidden. For this, the best approach is to define a default template for the control.

The default template is basically the style that is applied to the control in the absence of designer requests to the contrary. Practically, it is exactly the same as any other style that you would create. What makes it different is that the user of the custom component does not need to do anything to have the style applied.

In order to accomplish this feat requires three steps. The first has been true since Silverlight 2, that being that the style needs to be placed into a file named Generic.xaml. In the past it was sufficient to place the style in said file and set the TargetType of the style to be the custom control. However at Silverlight 3, two additional requirements were added. The first is that the Generic.xaml needs to be placed into a directory called Themes. The second is that the following line of code needs to the constructor for the custom control.

this.DefaultStyleKey = typeof(customcontrolname);

Once these conditions have been met, the default style will get picked up. It was the last two steps that stymied me, as many of the existing posts talk about one, but not both of the requirements.

As a convenience, there is now a TemplatedSilverlightControl template that actually sets up the necessary files, directory and code to make all of this work without further thought. And I like not having to think (other than remembering to use the correct template, that is).

Getting Value from your Data

For those of you who are not on the ObjectSharp mailing list, you might not be aware that next week we have another in our Smart Breakfast series. This time it’s David Chennels talking about Business Intelligence. You can find the details out here.

Now the term “Business Intelligence” is one of those amorphous phrases that have the potential to make people crinkle their nose. It has the good buzzwords to entire management and it’s vague enough so that you can put many different technologies under that umbrella. If you’re a geek in the Microsoft space, typically business intelligence includes the OLAP and Analysis Services parts of SQL Server, maybe a third-party tool to visualize the data (if Reporting Services isn’t enough) and perhaps Integration Services.

But those tools have been around for a while. And, even though there is no licensing fee added to be able to use then, they don’t seem to have much traction, at least in the companies that I’ve been working with. So what is the reason for this lack of interest?

From my perspective, the answer seems to be lack of awareness. If you ask any managers whether more information is better than less, most will want more. If you qualify the question by letting the managers specify the type and format of the information that is presented, the percentage answering in the affirmative goes up. And yet, even though the information is already stored in the corporate database and the tools to create the desired reports are readily available, nothing is done.

And what is the solution? Education. Spend some time getting up to speed on what you can do with the tools already at your disposal. Is the creation of a business dashboard a zero-effort project? No. But it’s probably much less effort than you think. And in the current business environment, doesn’t it make more sense to find a way to use your existing resources to their fullest event? Of course it does.

So take a morning to learn about the possibilities. More specifically, take the morning May 28th and come to the ObjectSharp Smart Breakfast on Business Intelligence. Along with a good breakfast, you’ll learn about some tools and techniques that can make an immediate difference to your business. Now that’s really getting value.

Getting Trained in an Economic Downturn

I’m sure that, for the vast majority of the readers of my blog, becoming more productive with your programming tools is a desirable goal. Not all developers go out of their way to advance their skills, but the very fact that you read blogs means that getting better is of interest to you. And, for most companies, they would also like you to make better use of your existing tools. It’s certainly obvious that it’s in your company’s best interest for this to happen, even if they don’t go out of their way to explicitly advance your skills.

And this is the ugly truth for most companies. In the best of times, a large number of companies don’t provide any significant budget for formal training. Usually developers are expected to pick up any new skills on their own time. Or, worse, they are expected to apply new technologies without spending any ‘exploratory’ time with them. As most of your are aware, the first time you try a new technology, the result is usually only partially successful. Only after you have worked with it a few times does it become possible to take full advantage of it. And yet, management is reluctant to pay for training classes, tech conferences, or even a programming book that will help you get ‘into the zone’ for the stuff that would make a difference in your day-to-day efforts. Here's a few suggestions that might, possibly get your manager to approve educational expenses, even in the economic conditions that exist today.

Working with Books

Over the years, I have worked with a number of different companies. Each of them takes a slightly different view of what appropriate training costs are. For companies that have a large number of developers and a small educational budget, sometimes books are all that fit. For some companies, creating a library of programming books is a viable books. Your company could purchase well-reviewed (reviews are easy to find on Amazon) programming books on the relevant topics. Employees could then ‘borrow’ books that were appropriate to their current tasks. The books end up being purchased just once, but can be shared between developers as the need arises.

A more high-tech solution to the problem can be achieved with a solution to the on-line technology book site Safari. Safari allows for books to be searched electronically and even be downloaded (in a PDF format) or even printed on an as needed basis. This is a decent mix between the need to search for a specific answer and still being able to read a book cover-to-cover when called for.

However, a corporate library is not always the best solution. Finding answers in a book requires, in many cases, that you have some inkling of the solution beforehand. At a minimum, you need to frame your query appropriately, something that is as much art as science. And the pace of technology advances means that books are almost always going to lag new technology and best practices by a period of months, if not years.

Selling Management on Training: Speak Their Language

When you want to convince your boss to let you go to a conference or attend a course, the first thing to do is look at the expenditure from their perspective. After all, the cost of the training is an expense to them. If there is no corresponding benefit, it becomes difficult to justify spending the monies. And, ultimately, you need to convince management that the benefits that they will gain are more than the money that they will spend.

In general, you will find that the attitude that a company has towards the training of developers is dictated by how the company makes money and who is responsible for helping to making that money. Usually, companies whose product is technology-based tend to be better at providing and paying for skill improvements for their employees. When developers productivity is closely aligned with corporate revenues, it is easier to get the boss’ attention. However, if you work on an application that has no direct correlation with how the company makes money, you’re much more likely to face an uphill battle.

But regardless of where you fit in this spectrum, focus your arguments on what they get out of sending you across town or across the country. Make the conversation about their Return on Investment. Show that the training will have concrete and immediate value to the company and you’re a lot closer to getting approval.

One way that you might be able to do this is to offer to share materials and experiences with your team upon return. At ObjectSharp, we call these sessions ‘Lunch & Learns”. You many know them as “Brown Bag Training”. By offering to present such a session after your conference or course, your company gets to spread some of the benefits of sending one person on training across multiple people. And your team benefits from having the new technologies couched in terms that are directly relevant to your environment.

In some cases, it’s also possible to get the trainer to offer to help with these sessions. This is something that ObjectSharp offers to attendees of our courses. We’re more than happy to have one of our instructors speak to your company about the newest technologies. While any course is on-going, instructors work hard to make the content relevant to you. To accomplish this, we ask about the kinds of projects that are being worked on and where the technology will be applied. So by having an ObjectSharp instructor give the Lunch & Learn, you get a person who is well-versed in the technology, but who also has a basic understanding of how it will fit into your corporate development plans.

You might consider shouldering some of the burden of training yourself. I don’t necessarily mean to pay for it directly. But if you take your time to attend user group meetings and Code Camps (both of which take place in non-work hours), you show a dedication to improving your skills that might make a difference. At a minimum, you will get some insight into the latest technologies, even if it’s not quite the same personalized and intensive hand-on experience that going on a course might be.

Finally, I’d like to leave you with one final, and surprisingly creative, argument. One of the most common questions we get from potential training clients is 'What if I train our developers and they leave?'" Our answer is invariably 'What if you don’t train them and they stay?' This usually gets an 'Aha' moment from management, followed by a realization that perhaps investing more in staff development might not be quite the pure expense that they think.