Most people ask whether a WCF LOB Adapter is in fact a
WCF service. The answer is no, it is not. WCF LOB Adapters are built on
top of the WCF channel model and exposed as custom WCF bindings. This
enables a client application to communicate with WCF LOB Adapters as if
they are classic WCF services, but such similarity also confuses many
developers. To understand this better, let's take a very brief excursion
into WCF fundamentals.
1. WCF Endpoints
To establish a
communication process with clients, a service must expose at least one
endpoint. The WCF endpoints consist of three parts known as the "A, B,
and C" of the WCF. The three parts are as follows:
Address: This takes the form of the URI that specifies the address where the service listening for incoming messages can be reached.
Binding: Bindings specify a communication protocol when the message is sent to a particular address.
Contract: Contracts specify what operations and data types are supported by the service.
Communication between client and service is conducted through a so-called communication channel. When you instantiate the ServiceHost
class, it builds a channel listener, which in turn builds a
communication channel for the service. On the client side, the proxy
creates a channel factory that is responsible for building an equivalent
communication channel for the client. The channels have a layered
structure where each layer or binding element in stricter terms performs
its own part of message processing as the message goes from one layer
to another, as shown in Figure 1.
As you can notice, the bottom layer in the communication channel is a
transport layer, and that's exactly where WCF LOB Adapter fits within
the channel stack.
2. WCF Transports
Out of the box,
WCF supports a few predefined transports such as TCP, Named Pipes, HTTP,
and MSMQ, but being designed with extensibility in mind, WCF allows you
to use your own custom transport components tailored to your specific
needs. If you take a look at the sample adapter code provided for this
chapter, you will see that the core adapter class is derived from the System.ServiceModel.Channels.TransportBindingElement class. Figures 2 and 3 show the message flow for the WCF LOB Adapters in inbound and outbound exchanges.
As you can see in the outbound
scenario, the WCF LOB Adapter, instead of sending the message over the
network, just communicates with the LOB system and sends a response to
the client application.
In the inbound scenario, the
WCF LOB Adapter monitors the target LOB system for particular events and
generates a notification message containing event-specific data for the
hosting application.