A somewhat hidden WCF Test Client feature

Lately I have been working on an Azure project for a client (if you haven’t noticed from my Azure-centric blog posts as of late). A part of this, we have built a WCF service that exposes the functionality that we need. However, we are not actually building a client, only the service. So we don’t have a great way of testing the service. This is obviously where the “WCF Test Client” comes in.

For those of you who don’t know what this is, it is a small client that hooks up to any available service and creates a proxy for you. You can then use this proxy through the interface and call your service.

If you create a new WCF Application in VS2010, pressing F5 will actually start it for you. If you aren’t doing it that way, you can start it yourself by pulling up a Visual Studio command prompt and executing wcftestclient.exe. And yes, you need the VS command prompt as it has some extra paths registered. Otherwise you have to go and find the application, which is in <PROGRAM FILES>\Microsoft Visual Studio 10.0\Common7\IDE.

Ok…so using it is fairly simple. Just point it at you service and you are done… It looks like this

image

In this case, I have created a service that looks like this

namespace WcfService1
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(string[] values);
}
}

Beautiful right…!? Well, the important part is not how complicated or simple the interface is, the important part is actually the parameter to the method GetData(). It is an array of strings.

Pulling up this method in the test client gives us this view

image

which is great. It has figured out that it has a parameter called “values”, and that it is supposed to be an array of strings. But the question is how we set it?

Well, if you know, you can stop reading right now. If not, then it might not be too obvious.

If you select the “length=0” cell, you get a drop-down. Sweet! But if you drop it down, you only get to choose “(null)”. There is no way to select a new array and set the size of it.

If you haven’t used it before, I can tell you that if the parameter is a object of some kind, opening the drop-down lets you create a new instance of it…

So what do we do? Well, a colleague of mine showed me that if you enter the cell’s text and change the 0 to a 1 or whatever length you need, it changes the array length and gives you this

image

And all of the sudden you can populate the array with data!

Ok, so you might already have known this, but if you didn’t (like me) it is pretty neat. From a UX perspective it is crap! Especially when you look at the next nifty thing.

If you happen to set the value to “null” using the drop-down, or by typing “(null)” (without the quotes) there is no way to set the value back using the drop-down. But if you manually type in “length=X”, you automagically get an array with the length of X.

That was my short post about what I consider being a somewhat hidden, but great, feature in a pretty useful tool. The only downside to using WCF Test Client is that it doesn’t support authentication very well. So if you start using some form of authentication, you might be better off with another tool.

At some point, I will get back to the “another tool” thing, and show how to easily load test your WCF services. But it will have to wait to another day…sorry!

Comments are closed