Tag Archives: WCF Proxy class

How to generate WCF Client Proxy Class using svcutil.exe

I wanted to use wcf because I read about it and like the power and clean implementation which is highly configurable without a lot of effort. I have used and made many clients for web services using Visual Studio .Net and all it requires is to know where the web service is hosted. When you add a service reference and pass in a url where it is hosted (WSDL) the IDE generates a proxy class and WOW !! there you go… Call the methods in ur client, no fuss at all clean , nice and smooth. I was under the impression that WCF is esentially the same and support many other types of bindings like http,tcp blah blah ….. So i started developing the Kool WCF server client application. Little did I know about generating the client proxy class using svcutil.exe . I knew that you can generate proxy classes using svcutil.exe but that is a painful painful process. A little up and down and it gives you exceptions that are very easy to understand [ Devilish smile ] . So to save you the time and effort that you will have to put it to generate proxy classes I will show you the exact app.config file and how to use the svcutil. You can simply copy and paste it and be happy [just rename the Contracts , end point info according to your own and you are good to go] …

I have changed the font to BOLD whatever i was missing and was required by svcutil to generate the proxy class that I used.
Here is my app.config in the Hosting Application (server) from where the service would be run:

<?xml version=1.0 encoding=utf-8 ?>





        <behavior name=mex>

          <serviceDebug includeExceptionDetailInFaults=true />

          <serviceMetadata />





      <service name=WCFServiceLibrary1.service1 behaviorConfiguration =mex>

        <endpoint address=net.tcp://localhost:6587/Service1/




                  contract=WCFServiceLibrary1.IService1 >


            <dns value=localhost />







             contract=IMetadataExchange />



            <add baseAddress=net.tcp://localhost:6587/Service1/ />







        <binding name=TestBinding maxBufferPoolSize=524288 maxReceivedMessageSize=65536 portSharingEnabled=false>

          <readerQuotas maxDepth=32 maxStringContentLength=8192 maxArrayLength=16384 maxBytesPerRead=4096 maxNameTableCharCount=16384 />

          <security mode=None />






Observe that there is an endpoint defined for metadata exchange called mex. This is used by the svcutil to generate the proxy class. The behavior node also contains a behavior named as mex. Now you are all set to use the svcutil.exe. Simply open the Visual Studio Command prompt from your startup menu à Visual Studio à tools and Command Prompt and type in the following command:

(Remember to replace the name to the service with yours as defined in the server configuration file)
Hope it helps and save you time and effort and I wish you don’t have to go through the pain of getting svcutil to work. Happy Coding !!

C:\Program Files\Microsoft Visual Studio 8\VC>svcutil.exe  net.tcp://localhost:6587/Service1/mex

This will generate two files service1.cs (proxy class for the client) and output.config (the app.config for the client). Enjoy !!









Filed under 1