WCF - Creating the client

In our previous article we see how to host the WCF service in a console application. Now lets see how to consume the service.
  1. Open Visual Studio 2008
  2. Create a Command Line application (File -> New -> Poject -> Visual C# -> Windows Application -> Console Application)
  3. In the solution explorer right click and click Add Service Reference (or Project Menu -> Add Sericce Reference)
  4. What this Add Service reference does. It creates the proxy classes for you automatically. So your client application will create the proxy object and will call the service thro' proxy object. Also it automatically creates app.config for you and place the necessary config information to access the service.
  5. Now open the Program.cs file. Add the below code in the main method.


WCFTutorialClient proxy = new WCFTutorialClient();
proxy.Open();
Console.WriteLine(proxy.GetData(10));
proxy.Close();
Console.ReadLine();

Now you run your application.

No comments:

Post a Comment