Simple WCF Binding Configuration example

In the previous post we moved the config code into a App.config file. Now let’s configure the bindings for the EchoService. A WCF binding for a Service Endpoint, combines the transport protocol (MSMQ, HTTP, TCP…), message format (JSON, XML, MTOM…) and message protocol (none, WS, SOAP…). WCF ships with the most common binding scenarios and a CustomBinding for creating your own binding. Here’s an overview of the most common configuration elements.

Configuration Element Description

<basicHttpBinding>

Basic SOAP like ASP.NET Web services (ASMX)-based services.

<wsHttpBinding>

Full fledged SOAP and WS protocols

<netNamedPipeBinding>

Named Pipes. A secure, reliable, optimized binding that is suitable for on-machine communication between WCF applications.

<netMsmqBinding>

MSMQ. A queued binding that is suitable for cross-machine communication between WCF applications.

<netPeerTcpBinding>

TCP peer-to-peer. Secure, multi-machine communication.

<webHttpBinding>

RESTful web service.

The configuration example of the EchoService sets the BasicHttpSecurityMode to Transport. This sends all service communication over SSL/HTTPS, so the service need some kind of SSL certificate (not shown here).

<?xml version="1.0" encoding="utf-8"?>
 
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBindingConfig">
          <security mode="Transport">
            <transport clientCredentialType="Certificate" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="BehaviourMetaData">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="BehaviourMetaData" 
               name="WcfServiceLibrary.Echo.EchoService">
        <endpoint address="http://localhost:8080/EchoService" 
                  binding="basicHttpBinding"
                  contract="WcfServiceLibrary.Echo.IEchoService" 
                  bindingConfiguration="BasicHttpBindingConfig" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>