WCF - Binding & Behavior


    WCF - Binding & Behavior

Binding :

  • Binding demonstrates the communication of a client with a service. 
  • One of the client will access SOAP using http and other client will access Binary using TCP.

Sample Code :

<system.serviceModel>
    <services>
        <service name="WikiTechy_WcfServiceLibrary.Service1">
    <host>
        <baseAddresses>
            <add baseAddress ="http://localhost:8732/Design_Time_Addresses/WikiTechy_WcfServiceLibrary/Service1/" />
        </baseAddresses>
    </host>
        <endpoint address ="" binding="wsHttpBinding"   contract="WikiTechy_WcfServiceLibrary.IService1">
            <identity>
                <dns value="localhost"/>
            </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>
<behaviors>
    <serviceBehaviors>
        <behavior>
            <serviceMetadata httpGetEnabled="True"/>
            <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
    </serviceBehaviors>
</behaviors>
</system.serviceModel>	

Explanation :


    App.config file is automatically created in a WCF Service Library application to indicate the configurations for address, endpoints and bindings of a service.

    The line <service name="WikiTechy_WcfServiceLibrary.Service1">  defines a name for the service application as WikiTechy_WcfServiceLibrary.Service1.

    The line <endpoint address ="" binding="wsHttpBinding" contract= "WikiTechy_WcfServiceLibrary.IService1"> defines the endpoint of the service that is exposed to clients to indicate the address of the service and its binding methodology as wsHttpBinding and the contract interface of the service as WikiTechy_WcfServiceLibrary.IService1.

The line <endpoint address="mex" binding="mexHttpBinding"contract="IMetadataExchange"/> defines another endpoint of the service to expose the metadata of the service, that eases the task of configuring the service by clients. This endpoint uses mexHttpBinding binding and IMetadataExchange contract.

    The <behaviors> section defines a <serviceBehaviors> to control the service features line endpoint, address and contract during the runtime.

    The element <serviceMetadata httpGetEnabled="True"/> indicates a Boolean value to decide on the publishing of service metadata via a HTTP/Get request. Default is false. But here it is set to “True”.

    The line <serviceDebug includeExceptionDetailInFaults="False" /> is a flag that returns error details when debugging the code.