In last post Implementing WCF service in code we saw how to create a client using c# code.
Today we will see how to create a client using Configuration files which is quite simpler than writing in a code.
* For ease of developers WCF provides ASR (Add Service Reference) feature as WCF is protocol independent and supports a variety of serialization, encoding, and security mechanisms, ASR offers great flexibility in providing support for manageability, performance, and security.
* The ASR feature of Visual Studio is used to obtain metadata from a WCF service and generate a proxy class and configuration file.
Steps to add ASR:-
We just need to right click on the ServiceReference node in Visual Studio 2008 and u will see the figure as follow
Behind The ASR:-
* Behind the scenes, ASR calls svcutil.exe which invokes a service’s MEX endpoint to query for its interfaces and to generate a proxy class and configuration file. The proxy class enables the client to access the service operations as if they were methods of a local class.
* The proxy class uses WCF classes to build and interpret SOAP messages according to the
contract defined by the service endpoint. The configuration file stores the
ABCs of the service.
* This dialog calls the svcutil utility to create a source code file that implements
the proxy class in the language of the project. It also creates an app.config file with a <Syste.ServiceModel> node that stores the address, binding, and contract information necessary to call the endpoints.
* As an alternative to using ASR, you can also use the svcutil utility directly. This utility, found in the C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin folder, takes many switches, and help is available by using the E8 switch from the command line. The utility accepts metadata as input and can produce various forms of output. The metadata can come from the DLL that implements the class, from a WSDL file, or from the WSDL returned by a WS-Metadata call to a running service.
Regardless of which technique is used to generate the proxy and configuration
file, svcutil.exe produces the same result.following code shows the configuration file
<?xml version="1.0" encoding="utf-8" ?>
<add key="UserName" value="ServiceTester"/>
<add key="Password" value="test123#"/>
<readerQuotas maxDepth="32" maxStringContentLength="16384"
<reliableSession ordered="true" inactivityTimeout="00:10:00"
<transport realm="" />
Hope this post will help you out in creating client using configuration files.
For WCF basics go through the following link
WCF # 1 – WCF Introduction (ENDPOINTs)