The fourth step involves creating the Windows Communication Foundation (WCF) client. It can be created using a Service Model Metadata Utility Tool (svcutil.exe) that can be found inside the Visual Studio SDK. This utility tool enables to extract the metadata associated to the WCF service and auto-generates a managed code for WCF service proxy in the specified programming language. It also generates a configuration file containing the information about WsDualHttpBindingand service endpoints which enable the client to communicate with the WCF Service.
Steps to Create a WCF Client
1. Add a new Console Application into the same WCFService solution by selecting its template from under the File menu -> New Project option.
2. In the Name box enter WCFService_Client as application name and press ok to create an empty console application.
3. After creating the console application, it will show the Program.cs file by default containing the following Main method code:
5. Now before proceeding further we need to create a proxy class using Service Model Utility Tool. Locate the tool inside the Microsoft SDK under the following path:
For x64 windows:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin
For x86 windows:
C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bin
First run the WCFService application to self-host and run the created WCF service then open the command prompt and change directory to the above specified path and run the following command to generate the managed source code in C#:
svcutil.exe /language:cs /out:wcfServiceProxy.cs /config:app.config http://localhost:5000/WCFService/Sample
After executing the above comment it will generate two output files inside the located tool path in the command prompt where the svcutil.exe exists. It will generate wcfServiceProxy.cs and app.configfile there. The Service Model Metadata Utility Tool will generate the following code in wcfServiceProxy.cs file:
Responses
0 Respones to "Creating a WCF Client"
Post a Comment