Home > WCF > WCF # 6 – Create a CLIENT for a WCF Web service(Creating/Implementing a Client for a WCF Service using Configuration files)

WCF # 6 – Create a CLIENT for a WCF Web service(Creating/Implementing a Client for a WCF Service using Configuration files)

Hi Geeks,

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

 

image

 

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.

svcutil http://localhost:8000/MyWCFService/mex/

-config:app.config

-out:generateproxy.cs

 

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" ?>
<configuration>
    <appSettings>
        <add key="UserName" value="ServiceTester"/>
        <add key="Password" value="test123#"/>
    </appSettings>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IBCIService
                    closeTimeout="00:01:00"  openTimeout="00:01:00
                    receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false
                    hostNameComparisonMode="StrongWildcard
                    maxBufferPoolSize="5565536
                    maxReceivedMessageSize="5565536"
                    messageEncoding="Mtom" 
                    textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="16384
                        maxArrayLength="16384"
                        maxBytesPerRead="16384
                        maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="None">
                        <transport realm="" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address=”http://localhost/MyService/MyService.svc
                            binding="wsHttpBinding
                            bindingConfiguration="WSHttpBinding_IBCIService"
                            contract="MyService.IMyService
                            name="WSHttpBinding_IMyService" />
        </client>
    </system.serviceModel>
</configuration>

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)

 

Thanks

Advertisements
Categories: WCF
  1. Rohit
    August 17, 2011 at 5:32 pm

    I’m going to start studying WCF..
    I’m sure i’ll get a lot from your posts..
    Keep it up 🙂

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: