VSTS Load Testing Deal of the Day: Why you need to buy a VS 2008 Load Agent before April 12th, 2010

There are important licensing changes happening imminently with VSTS as part of the transition from 2008 to 2010:

  • The current VSTS 2008 Test Edition can load test up to the limit of your machine. On a good day, this is 1000 users. That satisfies a lot of the cases where people need to do load testing. If it’s not, and you have multiple testers, you always all run load from your own machines, however you don’t get the same unified collection of statistics – that’s what the Load Agent & Controller software is for. It’s not a huge deal, and that is why most people don’t buy Load Agents.
  • If you did need centralized collection of statistics, you’d want to buy a number of load agents, one for each CPU, at least in the 2008 SKU. If you wanted to test 10K users, you’d probably want 10 licenses (at least).  But that is changing.
  • In 2010, load testing licensing is no longer done by the CPU, it’s done by the virtual users!
  • When you upgrade to VS 2010 Ultimate come April, your load testing ability changes to only 250 users from your workstation copy of Visual Studio 2010 Ultimate. If you want to test more, you’ll want load agents. The 2010 Load Agent SKU will give you 1000 virtual users. If your hardware is not up to snuff, or your web tests are intensive, you can install a single 2010 SKU on any number boxes, but you’re limited to a total of 1000 users per SKU that you purchase.

This all sounds rather terrible, but as part of the transition, MS is offering this:

If you have purchased a 2008 Load Agent with Software Assurance, as part of the upgrade to 2010, they will give you 5x1000 Virtual Users in the 2010 Load Agent SKU. Wow!

For your benefit of pricing, that means if you buy a 2008 Load Agent with SA today, for about $8,000 you will get 5000 users in 2010. That’s a very good deal. If you wait until after April 12th, you will no longer be able to buy the 2008 SKU and you’ll have to buy the 2010 SKU. At about $8,000 per 1000 users. So if you wanted to test 5000 users come April 12th and you didn’t take advantage to get in on this deal, it will cost you 5x$8000 = $40,000! I’d say that an 80% discount is pretty good – snap it up today.

If you need help purchasing a license prior to April 12th, drop me a note at bgervin @ objectsharp.com and I can hook you up.

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.

Enter the Stargate Destiny, courtesy of Silverlight, DeepZoom, Photosynth.

This may result in a “geekasm” – you’ve been warned.



How’d they do it?

MGM Stargate Case Study

Code Contracts at Toronto VB User Group

On Wednesday past, I did a Code Contracts presentation to the Toronto Visual Basic User Group. It was a continuation of my whirlwind ‘April Presentation Tour’, in that it was my third presentation in a week and the third of five that I’m doing in April. Tee shirts for the April Presentation Tour were available for sale from vendors as you left the arena

I have posted the slides and the source code to the following links:

Slides: Here

Source Code: Here

If you have any questions, please feel free to drop me a comment or an email message.

Having an Out-of-Browser Silverlight Experience

The fundamental philosophy used to develop the off-browser functionality for Silverlight applications was to reduce the friction surrounding the moving of the application from in-browser to out-of-browser. Specifically, there is no separate download that is required to take a Silverlight application off-line. As a developer, you need to make a change to the manifest to support installation, but nothing more than that. And because the off-browser application runs in the same sandbox as the in-browser application, there are also no security warning messages on installation.

From the user’s perspective, there are two methods to take the application off-browser. The first is the right click on the application. A second option (besides the Silverlight Configuration that has always been there) is visible to indicates that the application to be installed. Also, it is possible to place a button on the application that will install the application.

The manifest is where most of the information used in the installation exists. The name, description and icons related to the application are stored there, along with the flag indicating whether the application can be taken off-browser.

Updating the Silverlight application is exactly the same as the traditional Silverlight application. Which is to say that updates are downloaded and installed automatically. This keeps it consistent with the Silverlight model, where new versions are automatically picked up. The biggest difference is that once a new version is detected and downloaded, the Silverlight application does not automatically terminate and start running the new version. It waits until the next time that the application starts before launching the new version.

Warning – in the beta version, there appears to be a bug associated with updating from your localhost. In the words of the Silverlight PM, it’s a little flaky.

In terms of interacting with the client, an off-browser Silverlight app still has access to the Insolated store. And through the OpenFile and SaveFile dialogs, access to the local file system. There is  a quota on isolated storage, but it is increased to 25MB from it’s current size of 1MB. That’s nice and probably sufficient for most applications.

There are still a number of open questions about off-browser Silverlight applications. Is there an event raised when the application is closed (this is done through Javascript in normal Silverlight applications)? Is there a mechanism that simplifies serialization and synchronization? Should there be a way to uninstall the application other than by right-clicking on it (what if the app can’t load)? I’m sure time and the need to make this work in the real world will provide answers.

The Patch I Didn’t Even Know I Needed

I have been working with WPF and Silverlight pretty steadily for the past 6 months or so. And thanks to Rocky Lhotka, a problem that I didn’t even realize I had has been (probably) corrected.

The problem was that occasionally Visual Studio would just go away. No warning. No error. Just disappear. It didn’t happen that often for me, but I have had awkward moments while teaching a course. Even in that situation, neither I, nor any of the students did anything but shrug, chuckle and restart. These things do happen in the world of software development. The fact that we were willing to just accept it unquestioningly is a blog post for another day.

However, while perusing my blog roll yesterday, I came across this post from Rocky. It talks about a hotfix for a problem that causes Visual Studio to just disappear. Way too coincidental. A quick download and, hopefully, I’m inoculated from this issue going forward. If you’re using WPF in Visual Studio, it’s a fix you might strongly consider.

Generic Implementation of INotifyPropertyChanged on ADO.NET Data Services (Astoria) Proxies with T4 Code Generation

IMG_4855 Last Week Mike Flasko from the ADO.NET Data Services (Astoria) Team blogged about what’s coming in V1.5 which will ship prior to VS 2010. I applaud these out of band releases.

One of the new features is support for two-way data binding in the client library generated proxy classes. These classes currently do not implement INotifyPropertyChanged events nor project into ObservableCollections out of the box.

Last week at the MVP Summit I had the chance to see a demo of this and other great things coming down the road from the broader Data Programmability Team. It seems like more and more teams are turning to T4 Templates for code generation which is great for our extensibility purposes. At first I was hopeful that the team had implemented these proxy generation changes via changing to T4 templates along with a corresponding “better” template.  Unfortunately, this is not the case and we won’t see any T4 templates in v1.5. It’s too bad – would it really have been that much more work to invest the time in implementing T4 templates than to add new switches to datasvcutil and new code generation (along with testing that code).

Anyway, after seeing some other great uses of T4 templates coming from product teams for VS 2010, I thought I would invest some of my own time to see if I couldn’t come up with a way of implementing INotifyPropertyChanged all on my own. The problem with the existing code gen is that while there are partial methods created and called for each property setter (i.e. FoobarChanged() ), there is no generic event fired that would allow us to in turn raise a InotifyPropertyChanged.PropertyChanged event. So you can manually added this for each and every property on every class – but it’s tedious.

I couldn’t have been the first person to think of doing this, and after a bit of googling, I confirmed that. Alexey Zakharov’s post on generating custom proxies with T4 has been completely ripped off, er, inspirational in this derivative work. What I didn’t like about Alexy’s solution was that it completely over wrote the proxy client. I would have preferred a solution that just implemented the partial methods in a partial class to fire the PropertyChanged event. This way, any changes, improvements, etc. to the core MS codegen can still be expected down the road. Of course, Alexey’s template is a better solution if there are indeed other things that you want to customize about the template in its entirely should you find that what you need to accomplish can’t be done with a partial class.

What I did like about Alexey’s solution is that it uses the service itself to query the service meta data directly. I had planned on using reflection to accomplish the same thing but in hindsight, that would be difficult to generate a partial class of a class I’m currently reflecting on in the same project (of course). Duh.

So what do you need to do to get this solution working?

  1. Add the MetadataHelper.tt file to the project where you have your reference/proxies to the data service. You will want to make sure there is no custom tool associated with this file – it’s just included as a reference in the next one. This file wraps up all the calls to get the meta data I’ve made a couple of small changes to Alexey’s -- Added support for Byte and Boolean (typo in AZ’s).
  2. Copy the DataServiceProxy.tt file to the same project. If you have more than one data service, you’ll want one of these files for each reference. So for starters you may want to rename it accordingly. You are going to need to edit this bad boy as well.
  3. There are two options you’ll need to specify inside of the proxy template. The MetadataUri should be the uri to your service suffixed with $metadata. I’ve found that if your service is secured with integrated authentication, then the the metadata helper won’t pass those credentials along so for the purposes of code generation you’d best leave anonymous access on. Secondly is the Namespace. You will want to use the same namespace used by your service reference. You might have to do a Show All Files and drill into the Reference.cs file to see exactly what that is. 
  4. var options = new {
        MetadataUri = "http://localhost/ObjectSharpSample.Service/SampleDataService.svc/$metadata",
        Namespace = "ObjectSharp.SampleApplication.ServiceClient.DataServiceReference"

That’s it. When you save your file, should everything work, you’ll have a .cs file generate that implements through a partial class an INotifyProxyChanged interface. Something like…..

public partial class Address : INotifyPropertyChanged
    public event PropertyChangedEventHandler PropertyChanged;

    private void OnPropertyChanged(string property)
        var handler = PropertyChanged;
        if (handler != null)
            handler(this, new PropertyChangedEventArgs(property));

    partial void OnAddressIdChanged()
    partial void OnAddressLine1Changed()

Clearing the Debugging Tooltip

On the scale of annoyances, this is not a huge one. But the solution is so simple, that it’s worth a quick post.

Have you ever been in the middle of debugging an application and used the hover functionality to display the current value of a variable? And expanded multiple levels to find the specific property that you’re looking for? Of course you have.

But have you ever been frustrated when the debugging view obscures a piece of code that you’re interested in? So that you have to close the debugging tooltip to see the code and then navigate through the hierarchy to get back to what you were looking for? Odds are that it has happened to you. It certainly happens to me frequently enough.

Fortunately, there is a solution. While the debugging tooltip is displayed, simply press the Ctrl key. This instantly makes the tooltip transparent. And when you release the Ctrl key, the tooltip reappears. Simple and elegant, just the way all solutions should be.

Thanks to Dave Lloyd and Brian Rasmussen for the information (same tip at different times).

Changing Generated Code in VS2008

Have you ever been dissatisfied with the code that is automatically generated by Visual Studio in response to various commands that you perform. For example, in VS2005, I got used to using the prop snippet to create properties. This snippet created a property declaration complete with a private backing variable. However, in VS2008, the prop snippet was modified to create a property declaration in the form of the automatic property declaration. That, to me, was annoying.

(Note to Microsoft: Please consider the existing snippets to be part of what you consider when looking at backwards compatibility. Create more snippets, sure. But please don’t change what the current snippets do…especially when the ‘better’ snippets are not actually better)

Or, consider the fact that, as more and more work is done in WPF, the need to ensure that business classes implement INotifyPropertyChanged grows. Adding or modifying a snippet to include the code to call PropertyChanged could be quite useful. It certainly has been for me.

Little known by most developers is the location for the snippets that Visual Studio provides. Or, what might be more interesting to intrepid developers, the snippets used by Visual Studio refactoring. All of these are found in %ProgramFiles%\Microsoft Visual Studio 9.0\VC#\Snippets\1033. The keyword snippets can be found in the Visual C# subdirectory, while the refactoring snippets can be found in the Refactoring subdirectory. Take a look at what’s there and you may be surprised how you can increase your productivity for mundane (and frequent) tasks.

“Fixing” the WPF Designer

If you use WPF on a regular basis, then I can take a good guess as the esteem in which you hold the designer. While it has it’s place, hard code WPF devs using XAML directly. It’s much each to get the result that you’re looking for quickly. The problem I’ve always had is that when you open a WPF file, even when you have disabled the design portion, there is still a significant time lag.

Thanks to Fabrice Marguerie who wrote this blog post which describes how to eliminate that annoying delay.

It’s nice to have less friction between me and my XAML. :)