WCF Architecture [Abstract from Professional WCF Programing]
At the heart of WCF is a layered architecture that supports a lot of the distributed application development styles.Figure 1-3illustrates the layered architecture of Windows Communication Foundation.
This layered architecture, which provides developers a new service-oriented programming model, is discussed in detail in the following sections.
Contracts
WCF contracts are much like a contract that you and I would sign in real life. A contract I may sign could contain information such as the type of work I will perform and what information I might make available to the other party. A WCF contract contains very similar information. It contains information that stipulates what a service does and the type of information it will make available.
Given this information, there are three types of contracts: data, message, and service. More detailed information about contracts is given in Chapter 6, so consider this a primer.
Data
A data contract explicitly stipulates the data that will be exchanged by the service. The service and the client do not need to agree on the types, but they do need to agree on the data contract. This includes parameters and return types.
Message
A message contract provides additional control over that of a data contract, in that it controls the SOAP messages sent and received by the service. In other words, a message contract lets you customize the type formatting of parameters in SOAP messages.
Most of the time a data contract is good enough, but there might be occasions when a little extra control is necessary.
Service
A service contract is what informs the clients and the rest of the outside world what the endpoint has to offer and communicate. Think of it as a single declaration that basically states "here are the data types of my messages, here is where I am located, and here are the protocols that I communicate with."
There is a bit more to it than this, and Chapter 6 covers this in greater detail. But for now, suffice it to say that a service contract is one or more related message interactions.
Policy and Binding
Remember the SOA principles discussed earlier? Remember the one that discusses policies? Here is where they come into play. Policy and binding contracts specify important information such as security, protocol, and other information, and these policies are interrogated looking for the things that need to be satisfied before the two services start communicating.
Service Runtime
The Service Runtime layer is the layer that specifies and manages the behaviors of the service that occur during service operation, or service runtime (thus "service runtime behaviors"). Service behaviors control service type behaviors. They have no control over endpoint or message behaviors. Likewise, endpoint and message behaviors have no control over service behaviors.
The following lists the various behaviors managed by the Service Runtime layer:
q Throttling Behavior: The Throttling behavior determines the number of processed messages.
q Error Behavior: The Error behavior specifies what action will be taken if an error occurs during service runtime.
q Metadata Behavior: The Metadata behavior controls whether or not metadata is exposed to the outside world.
q Instance Behavior: The Instance behavior drives how many instances of the service will be available to process messages.
q Message Inspection: Message Inspection gives the service the ability to inspect all or parts of a message.
q Transaction Behavior: The Transaction behavior enables transacted operations. That is, if a process fails during the service runtime it has the ability to rollback the transaction.
q Dispatch Behavior: When a message is processed by the WCF infrastructure, the Dispatch Behavior service determines how the message is to be handled and processed.
q Concurrency Behavior: The Concurrency behavior determines how each service, or instance of the service, handles threading. This behavior helps control how many threads can access a given instance of a service.
q Parameter Filtering: When a message is acted upon by the service, certain actions can be taken based on what is in the message headers. Parameter Filtering filters the message headers and executes preset actions based on the filter of the message headers.
Messaging
The Messaging layer defines what formats and data exchange patterns can be used during service communication. Client applications can be developed to access this layer and control messaging details and work directly with messages and channels.
The following lists the channels and components that the Messaging layer is composed of:
q WS Security Channel: The WS Security channel implements the WS-Security specification, which enables message security.
q WS Reliable Messaging Channel: Guaranteed message delivery is provided by the WS Reliable Messaging channel.
q Encoders: Encoders let you pick from a number of encodings for the message.
q HTTP Channel: The HTTP channel tells the service that message delivery will take place via the HTTP protocol.
q TCP Channel: The TCP channel tells the service that message delivery will take place via the TCP protocol.
q Transaction Flow Channel: The Transaction Flow channel governs transacted message patterns.
q NamedPipe Channel: The NamedPipe channel enables inter-process communication.
q MSMQ Channel: If your service needs to interoperate with MSMQ, this is the channel that enables that.
Activation and Hosting
The Activation and Hosting layer provides different options in which a service can be started as well as hosted. Services can be hosted within the context of another application, or they can be self-hosted. This layer provides those options.
The following list details the hosting and activation options provided by this layer:
q Windows Activation Service: The Windows Activation Service enables WCF applications to be automatically started when running on a computer that is running the Windows Activation Service.
q .EXE: WCF allows services to be run as executables (.EXE files).
q Windows Services: WCF allows services to be run as a Windows service.
q COM+: WCF allows services to be run as a COM+ application.