WCF: Creating the Proxy
In order to for the client to communicate with a WCF service, we need a proxy object. This can be quite a daunting task (and a little complicated to be honest). Luckily like a lot of things in .NET 3.0/3.5 there are tools provided to make our lives easier (you still have to know about them though), and WCF is no different. It has a little tool called "svcutil" which comes to the rescue.
So how do we create a proxy for our little WCF service (ChatService.exe for the demo app) using svcutil. Well I have read one thing that said you should be able to just start the WCF service, point svcutil at the running WCF service, and be able to create the client proxy that way. But I have to say, I could NOT get that to work at all. It seems to a common gripe, if you search the internet. So the way I got it to work was as follows:
- Open a visual studio command prompt, and change to the directory that contains the WCF service
- Run the following command line:
svcutil <YOUR_SERVICE.exe>
- This will list a few files, namely *.wsdl, and *.xsd, and a schemas.microsoft.com.2003.10.Serialization.xsd file
- Next you need to run the following command line:
svcutil *.wsdl *.xsd /language:C# /out:MyProxy.cs /config:app.config
- You now have 2 new client files, MyProxy.cs and app.config, so you can copy these to your client application
To give you an idea of what svcutil.exe produces in terms of client files, let's have a look. Here is the MyProxy.cs C# file that was auto-generated by svcutil.exe.