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 :

        <service name="WikiTechy_WcfServiceLibrary.Service1">
            <add baseAddress ="http://localhost:8732/Design_Time_Addresses/WikiTechy_WcfServiceLibrary/Service1/" />
        <endpoint address ="" binding="wsHttpBinding"   contract="WikiTechy_WcfServiceLibrary.IService1">
                <dns value="localhost"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            <serviceMetadata httpGetEnabled="True"/>
            <serviceDebug includeExceptionDetailInFaults="False" />

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.