Monday, October 10, 2005

Hello World - Creating a WCF Client

Let us create a client to the service which we created in the previous post. Creating a client can't be simpler.

 

  • Create a config and generate a proxy.
  • Call the service using the proxy.

 

To create the config one can use the svcutil tool provided in the WinFx SDK. Use the following command from the Windows Managed Build Environment Command Line (from the Client folder)

 

svcutil /config:Sendhil.Samples.HelloWorld.Client.exe.config http://localhost:8080/HelloWorld

 

Note that we are using the http endpoint. The svcutil MEX implementation currently supports only http. This is the reason we defined two base addresses when we defined the WCF service. The http address was just for the tool.

 

The proxy creates a file called tempura.org.cs as we haven't specified the namespace and file name.

 

Snippet 1:

 

using System;

using System.ServiceModel;

 

namespace Sendhil.Samples.HelloWorld

{

          public class HelloClient

          {

                   public static void Main()

                   {

                             HelloProxy proxy = new HelloProxy();

                             Console.WriteLine(proxy.SayHello("Sendhil"));

                             Console.WriteLine("Hit Enter to Exit");

                             Console.ReadLine();

                   }

          }

}

 

Save Snippet 1 as HelloClient.cs in the client directory.

 

Compile this into a console App using the following command line

 

csc /r:System.ServiceModel.dll /t:exe /out:Sendhil.Samples.HelloWorld.Client.exe HelloClient.cs tempuri.org.cs

 

Run the client, that is it.

 

Applies to: WinFx September 2005 CTP

0 Comments:

Post a Comment

<< Home