WCF client is a client application creates to expose the service operations as method. Any application can host a WCF client, including an application that host a service. Therefore it is possible to create a service that includes WCF clients of other services.
A client application is a managed application that uses a WCF client to communicate with another application. To create a client application for a WCF service requires the following steps:
- Get the Proxy class and service end point information
- Call operations.
- Close the WCF client object.
Using SvcUtil.exe we can create proxy class for the service and configuration information for endpoints. Example type the following sentence in the Visual studio command prompt, this will generate the class file and configuration file which contain information about the endpoints.
svcutil /language:vb /out:ClientCode.vb /config:app.config http://localhost:8090/MyService/SimpleCalculator.svc?wsdl
Add this class files in the client application. Then create the object for this class and invoke the service operation. Configuration information we got from the above step has to be added to the client application configuration file. When the client application calls the first operation, WCF automatically opens the underlying channel. This underlying channel is closed, when the object is recycled.
//Creating the proxy on client side MyCalculatorServiceProxy.MyServiceProxy proxy = new MyCalculatorServiceProxy.MyServiceProxy(); Console.WriteLine("Counter: " + proxy.MyMethod());
After using the object created in the above steps, we have to dispose the object. Channel will be closed with the service, when the object is cleared.