Introduction

WCF (Windows Communication Foundation) unifies the .Net communication capabilities into a single, common, general Web service oriented framework. A good WCF tutorial can be found here.

WCF separates how service logic is written from how services communicate with clients. Bindings are used to specify the transport, encoding, and protocol details required for clients and services to communicate with each other. Qpid provide a WCF binding: org.apache.qpid.wcf.model.QpidBinding. WCF Services that use the Qpid binding communicate through queues that are dynamically created on a Qpid broker.

How to use Qpid binding

WCF services are implemented using:

  • A service contract with one or more operation contracts.
  • A service implementation for those contracts.
  • A configuration file to provide that implementation with an endpoint and a binding for that specific contract.

The following configuration file can be used to configure a Hello Service:

<configuration>
  <system.serviceModel>   
     <services>
      <!-- the service class --> 
      <service name="org.apache.qpid.wcf.demo.HelloService">
        <host>
          <baseAddresses>
            <!-- Use SOAP over AMQP -->
            <add baseAddress="soap.amqp:///"   />
          </baseAddresses>
        </host>

        <endpoint
          address="Hello"
          <!-- We use a Qpid Binding, see below def -->
          binding="customBinding"
          bindingConfiguration="QpidBinding"
          <!-- The service contract -->
          contract="org.apache.qpid.wcf.demo.IHelloContract"/>
      </service>
    </services>

    <bindings>
      <customBinding>
        <!-- cf def of the qpid binding --> 
        <binding name="QpidBinding">
          <textMessageEncoding />
          <!-- specify the host and port number of the broker --> 
          <QpidTransport            
               host="192.168.1.14"
               port="5673" />
        </binding>
      </customBinding>
    </bindings>

    <extensions>
      <bindingElementExtensions>
        <!-- use Qpid binding element: org.apache.qpid.wcf.model.QpidTransportElement --> 
        <add
          name="QpidTransport"
           type="org.apache.qpid.wcf.model.QpidTransportElement, qpidWCFModel"/>
      </bindingElementExtensions>
    </extensions>

  </system.serviceModel>
</configuration>

Endpoints and bindings can also be set within the service code:

/* set HostName, portNumber and MyService accordingly */           
Binding binding = new QpidBinding("HostName", portNumber); 
ServiceHost service = new ServiceHost(typeof(MyService), new Uri("soap.amqp:///"));
service.AddServiceEndpoint(typeof(IBooking), binding, "MyService");
service.Open();
....
  • No labels