The WCF platform provides built-in support for a
range of distributed communication protocols, including transport and
message encoding protocols using channel bindings.
Available channel bindings include:
protocol channel bindings that determine security, reliability and context flow settings
transport channel bindings that determine the underlying transport protocol (including TCP and HTTP)
message encoding bindings that determine the encoding at the wire (including text/XML, binary, and MTOM)
Although these default
channel bindings will cover common communication scenarios, there may be
certain requirements that can only be accommodated via further
customization. For this purpose, WCF provides an extensibility model
with several extension points.
Before we explore the
extensibility model, we first need to establish how WCF can be
represented with two fundamental architectural layers.
WCF Layers
As shown in Figure 1, WCF is partitioned into two main layers: the service model layer and the channel layer.
The service model
layer essentially provides a programming model that enables solutions to
use WCF. For example, all the information about user-defined service
contracts is found in this layer.
Underneath the service
model layer is a shared message layer used as the transport and also
known as the channel layer. The channel layer provides several
communication channels and is also known as the channel stack.
Addresses and bindings defined in the service model layer provide the
mechanisms used to control the channel stack. Bindings define the
transport and addresses define the destinations of messages.
Layered Extensibility
Figure 2
further expands on the layered view by illustrating how the proxy and
dispatcher relate to the service model layer and represent touch points
for services. You’ll notice that underneath the proxy and dispatcher are
the protocol and transport channel stacks. The protocol channels are
used to process SOAP messages, add security, and add and remove headers,
whereas the transport channels are used to send and receive messages.
WCF
is extensible at the service model layer and at the channel layer. If
you need to make changes that affect service behavior, then you need to
ensure that service model extensibility is used. If the requirement
affects changes to the message at the wire level, channel layer
extensibility is used.
Channel Layer Extensibility
The WCF channel extensibility
model can be used to extend channels for non-supported transports such
as UDP and SMTP or other custom and proprietary transports.
Specifically, this form of extensibility at the channel layer allows
for:
the creation of new transports
integration with incompatible and proprietary systems
implementation of custom infrastructure protocols
The ability to create and
extend WCF with new transports can be used to simplify integration
between incompatible systems. For example, WCF channels can be
customized to talk RMI on the wire in order to integrate with a Java
application. Channel layer extensibility also allows for the creation of
custom infrastructure channels, such as proprietary SOAP-level
compression.
In the next example, the
address, binding and contract are set and associated with a host. The
binding indicates the runtime is going to construct a channel stack
optimized for TCP with binary as the message encoding for efficient
message transfer. The host.Open(); statement invokes channels and channel listeners to enable communication.
Example 1.
ServiceHost host = new ServiceHost(typeof(MyService));
Uri address = new Uri("net.tcp://temp/service/endpoint");
Binding binding = new NetTcpBinding();
Type contract = typeof(IContract);
host.AddEndpoint(address, binding, contract);
host.Open();