Testing WCF Services – Bindings

I’m pretty excited about Windows Communication Foundation (WCF) Services. I tend to think of WCF Services as highly customizable Web Services. I’ve been looking at testing WCF Services and am finding the main challenge is, not surprisingly, understanding WCF Services conceptually as well as learning the low-level details. A key WCF concept is bindings. A WCF binding specifies three things: the message transport (such as HTTP), the message encoding (such as text), and message protocol details (such as SOAP version). WCF bindings therefore represent sort of a meta-protocol for a client program and a server program to communicate. WCF ships with 11 system-provided bindings, and you can create custom bindings too. The most basic system-provided WCF binding is BasicHttpBinding. It specifies using HTTP, with text based SOAP version 1.1 messaging. The other 10 system-provided bindings are: WSHttpBinding, WS2007HttpBinding, WSDualHttpBinding, WSFederationHttpBinding, WS2007FederationHttpBinding , NetTcpBinding, NetNamedPipeBinding, NetMsmqBinding, NetPeerTcpBinding, and MsmqIntegrationBinding. When creating a WCF Service, you can specify the binding in one of two ways. The recommended approach is to place the binding in a configuration file. The alternative is to programmatically specify the binding. If you are hosting a WCF Service inside IIS, you could specify the binding in a configuration file by creating a Web.config file like this:
<?xml version="1.0" encoding="utf-8" ?>
      <service name="MyService" >
          contract="IMyService" />
        <binding name="Binding1">
If you wanted to programmatically specify the binding in the WCF Service, the code (in C#) would look like:
WSHttpBinding binding1 = new WSHttpBinding();
The main advantage to specifying the WCF Service binding in a configuration file is that is you ever want to change the binding, you can just change the configuration file without having to rebuild the Service. The main disadvantage of the configuration file approach is that you have critical information in a separate file.
Once you know what bindings are, the next concept one step up the WCF abstraction level is an endpoint. A WCF endpoint consists of an address, a binding, a "contract", and local implementation details of the endpoint.
This entry was posted in Software Test Automation. Bookmark the permalink.