WCF/WF - Proxy - Asked By Naresh Kumar on 02-Jun-11 06:09 AM

Hi All,

I am a beginner to WCF.

Created one sample service and hosted in Console application using Service Host class. How can I generate proxy using svcutil for this to add it to the Client.

Please advise.
Ravi S replied to Naresh Kumar on 02-Jun-11 06:35 AM
HI


Run svcutil.exe specifying metadata address

Open the visual studio command prompt or locate the svcutil.exe from the command prompt

c:\programefiles\microsoft sdks\windows\v6.0A\bin> svcutil.exe "http://localhost/managecrm/managecrm.wsdl" /language:C#

//use above if you want to generate the proxy in c#
c:\programefiles\microsoft sdks\windows\v6.0A\bin> svcutil.exe "http://localhost/managecrm/managecrm.wsdl" /language:VB

//Use above if you want to generate the proxy in VB
To Get the helpwith svcuitl.exe use the following command
c:\programefiles\microsoft sdks\windows\v6.0A\bin> svcutil

The output.config and proxy class will be generated in the "c:\programefiles\microsoft sdks\windows\v6.0A\bin"





Jitendra Faye replied to Naresh Kumar on 02-Jun-11 06:42 AM

Follow this example-

Assume in the App.config configuration file, in the Host application (Console Application), you have the following configuration:

    <system.serviceModel>
        <services>
            <service name="WCFFromScratch.Service1" behaviorConfiguration="serviceBehavior">     
                <endpoint address="Service1" binding="netTcpBinding" contract="WCFFromScratch.IService1" />
              <endpoint contract="IMetadataExchange" binding="mexTcpBinding" address="mexTcp" />
      <host>
                    <baseAddresses>
                        <add baseAddress="net.tcp://localhost:9000"/>
                    </baseAddresses>
                </host>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="serviceBehavior">
                    <serviceMetadata httpGetEnabled="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
    </system.serviceModel>

The first important thing to notice in the above is the line in bold. Using the *mexTcpBinding* enables exposing meta data for the TCP endpoint and hence, using now the Svcutil.exe as follows:


c:\Program Files\Microsoft Visual Studio 9.0\VC>svcutil /d:C:\ /o:serviceProxy.cs /config:app.config net.tcp://localhost:9000/mexTcp


The above is enough to generate a new proxy client class named *serviceProxy.cs* located in the *C:\* drive.

Notice how I used the *mexTcp* address, which is the one that exposes meta-data for the SvcUtil in order to be able to generate the proxy.


For more information on publishing meta-data for a service, check the following: How to: Publish Metadata for a Service Using a Configuration File
Naresh Kumar replied to Jitendra Faye on 02-Jun-11 07:00 AM
Thanks for your reply.

I have created service in class library say DemoService.dll, after build I will get the DLL. Then I have added the DemoService.dll in Console application to host the service using ServiceHost.

Now I want to run svcutil on the Service library DemoService.dll to generate the WSDL file. I struck here...

Please advise.
Jitendra Faye replied to Naresh Kumar on 02-Jun-11 07:46 AM

As i told in previous post,

using now the Svcutil.exe as follows:

c:\Program Files\Microsoft Visual Studio 9.0\VC>svcutil /d:C:\ /o:serviceProxy.cs /config:app.config net.tcp://localhost:9000/mexTcp



For more help follow this links also-

http://msdn.microsoft.com/en-us/library/aa751905.aspx
http://chakkaradeep.wordpress.com/2008/08/07/generating-wcf-proxy-using-svcutilexe/
Kirtan Patel replied to Naresh Kumar on 02-Jun-11 08:12 AM
here is how you can generate proxy in specific language in WCF/WF

svcutil /t:code /language=VB
  http://localhost:8731/Design_Time_Addresses/MyService/WcfService/
  /out:MyServiceProxy.vb /config:MyServiceProxy.config

Riley K replied to Naresh Kumar on 03-Jun-11 12:58 AM
Follow these steps

    To create a Windows Communication Foundation client



    Create a new project within the current solution for the client in Visual Studio 2010 by doing the following steps:

     1. In Solution Explorer (on the upper right) within the same solution that contains the service, right-click the current solution (not the project), and select Add, and then New Project.

     2. In the Add New Project dialog, select Visual Basic or Visual C#, and choose the Console Application template, and name it Client. Use the default Location.

     3. Click OK.

   2.

    Add a reference to the System.ServiceModel.dll for the project:
     1. Right-click the References folder under the Client project in the Solution Explorer and select Add Reference.

     2. Select the .NET tab and select System.ServiceModel.dll (version 4.0.0.0) from the list box and click OK.

    ms733133.note(en-us,VS.100).gifNote:
    When using a command-line compiler (for example, Csc.exe or Vbc.exe), you must also provide the path to the assemblies. By default, on a computer running Windows Vista for example, the path is: Windows\Microsoft.NET\Framework\v4.0.

   3.

    using System.ServiceModel;

   4.

    In Visual Studio, press F5 to start the service created in the previous topic. For more information, see How to: Host and Run a Basic Windows Communication Foundation Service.
   5.

    Run the ServiceModel Metadata Utility Tool (Svcutil.exe) with the appropriate switches to create the client code and a configuration file by doing the following steps:
     1. On the Start menu click All Programs, and then click Visual Studio 2010. Click Visual Studio Tools and then click Visual Studio 2010 Command Prompt.

     2. Navigate to the directory where you want to place the client code. If you created the client project using the default, the directory is C:\Users\<user name>\My Documents\Visual Studio 10\Projects\Service\Client.

     3. Use the command-line tool ServiceModel Metadata Utility Tool (Svcutil.exe) with the appropriate switches to create the client code. The following example generates a code file and a configuration file for the service.

        svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:8000/ServiceModelSamples/service