So, a few weeks ago, I was working on a WCF service and decided I was ready to test it. My first inclination was to write a few unit tests. Sorry, TDD folks--I know that should have been the first thing I did. Well, I didn't get very far with my unit tests, which will probably be the subject of a later blog post. So, on to Plan B.
Many months ago, I attended a session on WCF. During the course of the session, the presenter brought up--as an aside--the WCF Test Client. Instead of writing our lame console or winform apps to test our WCF services, Microsoft has provided us a tool to do all that work for us. All we have to do is point the WCF Test Client at our service and it will generate a proxy and present us with a GUI where we can select whatever method we're interested in to test. Easy, right? What could possibly go wrong?
So, I fire the thing up by pointing it to my service and the first thing I get is this error: Unrecognized option "targetclientversion" specified. Hmm. What's going on here?
Well, a little digging around and I find out that WCF Test Client is trying to run the svcutil.exe utility and pass it some switch called "targetclientversion". Ok. Let's take a look at svcutil and see what it has to say. By the way, where is svcutil anyway?
So, looking at wcftestclient.exe in .NET Reflector, I can see that the tool is looking in the Registry for the filepath to a Microsoft SDK which should include the svcutil utility. If no SDK filepath is present in the Registry, the tool will default to the v6.0 filepath. [Credit to this forum post for walking me through this.]
So, what SDK version of svcutil is WCF Test Client trying to use? Well, v6.0, of course (see the picture of my Registry)! That must be the problem: I know there's a new version of the SDK out there, I installed it not long ago. [Why did I install a 1.5 Gb SDK? Because I needed the 100k ASP.NET merge utility contained therein. No, I'm not bitter about that.]
Ok. Let's change that Registry filepath to the new SDK and fire up the Test Client again. It's gonna work this time, right?
Wrong. Enter in the next error: System.IO.FileLoadException: Could not load file or assembly 'svcutil, blah, blah, blah.' I give you Exhibit A and Exhibit B. It seems svcutil.exe in SDK v6.1 comes with added security features that didn't exist for svcutil in SDK v6.0. This feature was reported during the Orcas beta, but I haven't seen it reported for SDK v6.1. Fortunately, when I ran the fix suggested in that blog entry, I was able to resolve the problem and at least make svcutil viable again.
Ok, now where was I? Let's see...I:
- Discovered that my older SDK install (v6.0) was being used for various Visual Studio operations.
- Fixed my Registry entry so that wcfTestClient, and presumably other tools, will point to the most recent version of the SDK installed on my machine (in this case, v6.1)
- Discovered that svcutil in SDK v6.1 has permission problems that have to be relaxed via sn.exe
Ah. I'm ready to try the tool again...oh great. Guess what? I'm back to my original "targetclientversion" specified error. Now what gives? Well, some more digging with Reflector reveals that, indeed, wcfTestClient is trying to call svcutil with the command line switch "targetclientversion". The bad news is, it doesn't appear that svcutil--neither the version in SDK v6.1 nor the one in SDK v6.0--support a switch called "targetclientversion". (At least, I went to the command line and looked at the command line help and didn't see this switch listed for either version.)
I have no idea where this targetclientversion switch came from but it seems to me that, so long as it's not supported by a version of svcutil, the wcfTestClient tool is useless. So, I guess it's back to our lame console apps to test our WCF services. Sweet.
Update:
The plot thickens...I was looking at my Vista machine which runs Visual Studio 2008 and noticed that I have Windows SDK v6.0a installed on it. The svcutil.exe utility in that SDK is called version 3.0.4506.648. Looking at its command line help, I saw that it does include an argument named targetclientversion. Ah-ha! This version number is greater than the one found in SDK v6.1, even though one would assume that v6.1 is greater than v6.0a. I haven't actually tried running wcfTestClient on my Vista machine, but I'm sure it will work now that it can find a svcutil that supports the targetclientversion switch.