C#, CodeProject, Current Work, Employment, WCF, WPF

How To Create A WCF Client Proxy Without Having a Deployed WCF Service

At work we are currently using a very very Agile process, which involves 1/4 hourly builds, which was all going brilliantly with a WPF solution and some Mocks and some NUnit test projects. Then we got to the point where we had to start building our WCF service and have the WPF project obtain a new service reference client proxy based on the newly built WCF service project. This is easily achieved using NANT and wiring up dependencies in a NANT script, but we were not in a position where we could actual deploy the WCF Service with every build, due to the fact that we are hosting the WCF service inside a Windows service.

We could have also automated this using InstallUtil.exe to install the service, but this would have added more complexity to an already complex build arrangement within our CI build server AKA “Cruise Control”. We could have done it, but we simply wanted to be able to create a new service reference client proxy. Normally what one would do would be to add a service reference within Visual Studio, something like the figure shown below:


When you add a service reference using Visual Studio, you typically have to have, the service both deployed and running, and you then point the wizard at the deployed and running service address, which exposes some metadata which allows the wizard to be able to see information about the service. This will then create a bunch of items in Visual Studio, such as the following :


One of the these generated files is the service reference client proxy. In this case it is called “Reference.cs”, which if we examine a small section of it, contains all the DataContract / ServiceContract class definitions.


Which is fine, but as I stated above, what was needed for a continuous build environment (Cruise Control) was the ability to create this service reference client proxy class “Reference.cs” without a deployed service. Mmmm, how could we do that.

Well luckily there is a command line tool which can be run as part of a NANT script. This utility is called “svcutil.exe”, and has many options, which you can find using the svcutil.exe /? switch.

But to help you out here is what we had to do in order to duplicate the functionality provided by the Visual Studio wizard using just svcutil.exe.

It was a 2 phase operation, the phases are as follows:

Create WSDL from Dlls

You can create a WSDL by using the Dlls themselves, and then you can use the WSDL to create a service reference client proxy class. Here is how we did this.

Switch Description
/d: /d:<directory> Directory to create files in (default: current directory)
/reference: /reference:<file path> : Add the specified assembly to the set of assemblies used for resolving type references.


NOTE : You may have all your ServiceContract and DataContract classes all in one Dll, so in this case you would not need the /reference: switch, this is only need to link in additional Dlls.

Use WSDL to create WPF client service reference proxy class

Once we had a WSDL we could the use this to create the create a service reference client proxy class. We did this as follows:

Switch Description
/d: /d:<directory> Directory to create files in (default: current directory)
/l: Language C# or VB
/out: Name of output file
/noconfig Do not generate a client layer App.Config file
/s /serializable : Generate classes marked with the Serializable Attribute
/ct /collectionType: <type> : A fully-qualified or assembly-qualified name of the type to use as a collection data type when code is generated from schemas.
/ser: /serializer: Auto – Automatically select the serializer. This tries to use the Data Contract serializer and uses the XmlSerializer if that fails.
/tcv: /targetClientVersion:Version35 : Generate code that references functionality in .NET Framework assemblies 3.5 and before.
/n: /namespace:<string,string> : A mapping from a WSDL or XML Schema targetNamespace to a CLR namespace.
/edb /enableDataBinding : Implement the System.ComponentModel.INotifyPropertyChanged interface on all Data Contract types to enable data binding.


And that was enough for us to generate a new WPF client service reference proxy class in an automated manner, without the need to have the WCF service deployed and running.

Hope this helps someone out there

Employment, WPF

Creating A Brand

I have just got a new job which involves creating a new application in WPF. I initially applied for this job, as it represented a challenge, which I quite like. At the interview stage, I was shown an existing WPF application that the existing team had created. There was nothing really that wrong with it, but it somehow just didn’t feel that WPF like.

They had the tools to do a good WPF app, for sure, they are bright people (otherwise I would not have wanted the job), but they were approaching it like a WinForms app, and it just felt, well WinForms like.

Now with all the new WPF arsenal that we have at our disposal, there is really no need that a WPF app needs to look like a WinForms app.

Using things like Animations we can do some really cool things, to set a WPF app apart, but taking a step back, I firmly believe what makes a world of difference is a common set of styled/templated controls. That are used throughout the application.

If you take the time to re-style the existing controls, you can create some quite cool looking controls that still work just the same as the original controls do, but they just look better.

I really think this 1 step, can contribute is such a major way to the way the whole app is perceived, it worth the time you spend customising the controls.

For example let’s consider a ScrollViewer control, whos default appearance looks like this:



And how about a TabControl, which by default looks like this:


Now I am no expert with Styling/Templating, but in 2 hours last night I was able to come up with some pretty satisfactory Styles/Templates for both of these controls. These new Styles/Templates, aid in branding of the overall app.

For me personally, each of the native control types that I end up using in the new WPF application, I will be attempting to create a new version of it, which sets the app apart, and gives it a touch of difference.


In this figure there is a ScrollViewer contained within a TabItem (Item2). The overall TabControl has been altered to give the appearance you see here.

So by just spending a bit of time working with Styles/Templates you are able to create some pretty slick looking stuff. After all this screen shot is just a TabControl and a ScrollViewer, which looks nothing like the default control as shown below.



I’m sure most of you will agree, the benefits from creating your own control styles, will surely help create a brand for your application. So got for it, don’t be shy, give it a try, like I say these 2 styles took me about 2 hours last night.

PS: I am unable to share the code for these 2 control Styles as I will be using them as part of a project. Sorry


Some Other Areas That Ive Also Worked In

Obviously when one is employed (as I have been since I was about 18 or so, even during my degree) one has to be mindful of keeping customer sensitive information, private. As such I have worked on many many interesting projects that you would all love, but alas I can not share code for, as it is private customer data.

I can however state the application of some of the more exotic systems that I have worked on :

  • Colourant plant automation and recipe management system, for Clairol hair dye (yes them on TV)
  • Serial comms protocol definitions for some very wacky serial comms stuff, talking to C# code. My boss at the time did the code.
  • Assisted in the development of our own automation layer written entirely in C#, with support for OPC
  • Support for numerous blue chip UK based companies
  • Integration of Management Excecution Systems world wide for Procter & Gamble