Oct 2 2008

Using SvcUtil.exe to generate Client Proxy for TCP Endpoints

Category: WCFBil@l @ 09:22

I started lately learning WCF and going step by step with the concepts. However, today I was stuck by how to generate a proxy client class for a Host application that exposes a Service with a TCP endpoint.

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

Hope this helps,
Regards

Tags:

Comments are closed