Even though WCF has been around for a while now, I still have a lot of people ask me about the service model metadata tool (aka svcutil.exe). It seems as though quite a few developers find it to be rather cryptic and difficult to use. This is probably due to the large number of switches that are available. Given that you will likely need to use svcutil if you do very much WCF development, I have decided to post a short series on some of its capabilities.
Before I go any further, let me emphasize something that I have said again and again in various presentations. Even if you are using Visual Studio to directly add a service reference in your project, you are still ultimately using svcutil. Behind the scenes, Visual Studio is invoking svcutil with the necessary switches to generate your proxy and configuration file from the service that was referenced. If the default proxy and configuration that Visual Studio spits out is sufficient for your needs, good for you. But, sooner or later, you will probably find that you need to leverage svcutil in some capacity.
In this post, I am going to cover the basic process for generating a proxy with svcutil. Keep in mind there are a LOT of options available when generating a proxy, but I only intend to cover the basic concept at this point. Later in the series, I will go over some additional options in greater details.
To generate a proxy from a service that is currently running, simply run the following command:
svcutil /t:code http://localhost/myService /out:Proxy.cs /config:Proxy.config
Obviously, you would replace the parameters with your application values. This command simply tells the utility to generate code from the specified service url, store the proxy in a class file named Proxy.cs, and the corresponding configuration in a file named Proxy.config. Again, your service must be running for this to work. Furthermore, the service must provide an endpoint for the metadata exchange. Otherwise, there is no way to query the necessary metadata that is required to generate a proxy. If you aren't familiar with the process, I have a previous post about enabling the metadata exchange that can be found here.
It should also be noted that the default language is C#. If you want your proxy to use VB.Net, there is an additional language switch that can be specified: /language:VB