Visual Studio 2008 has made our WCF life a lot easier with the ability to self-host the services and also allow debugging in our service.
What if we were pushed to a situation wherein we need to use the tool svcutil.exe to create our proxy for the client…hmm…
To do so, we need to have our service running. Once the service is up and running, we could generate the proxy by the following command (replace the tags correspondingly) :
1: svcutil /t:code http://<service_url>
2: /out:<file_name>.cs /config:<file_name>.config
Here is my example :
1: C:\Users\Chaks\Documents\Visual Studio 2008\Projects\MyService\MyServiceHost>
2: svcutil /t:code http://localhost:8731/Design_Time_Addresses/MyService/WcfService/
3: /out:MyServiceProxy.cs /config:MyServiceProxy.config
4: Microsoft (R) Service Model Metadata Tool
5: [Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.648]
6: Copyright (c) Microsoft Corporation. All rights reserved.
7:
8: Attempting to download metadata from 'http://localhost:8731/Design_Time_Addresse
9: s/MyService/WcfService/' using WS-Metadata Exchange or DISCO.
10: Generating files...
11: C:\Users\Chaks\Documents\Visual Studio 2008\Projects\MyService\MyServiceHost\MyS
12: erviceProxy.cs
13: C:\Users\Chaks\Documents\Visual Studio 2008\Projects\MyService\MyServiceHost\MyS
14: erviceProxy.config
Now we can add this .cs file to the Client project and copy the .config file contents to the Client’s app.config file and execute the client
We can also instruct svcutil to generate the proxy in the preferred language we want :
1: svcutil /t:code /language=VB
2: http://localhost:8731/Design_Time_Addresses/MyService/WcfService/
3: /out:MyServiceProxy.vb /config:MyServiceProxy.config
But svcutil already identifies the language with the extension of our output file name