Monday, 13 June 2011

WCF Architecture

Windows Communication Foundation (WCF) is a platform, a framework if you will, for creating and distributing connected applications.
WCF is a programming model that enables developers to build service solutions that are reliable and secure, and even transacted. It simplifies development of connected applications and offers something to developers that they have not seen in quite a while—a unified, simplified, and manageable distributed system development approach.

WCF Architecture

At the heart of WCF is a layered architecture that supports a lot of the distributed application development styles. Figure illustrates the layered architecture of Windows Communication Foundation.

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.
There are three types of contracts: data, message, and service.
1.    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.
2.    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.
3.    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.”
A service contract is one or more related message interactions.
4.    Policy and Binding:
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 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:
  1. Throttling Behavior: The Throttling behavior determines the number of processed messages.
  2. Error Behavior: The Error behavior specifies what action will be taken if an error occurs during service runtime.
  3. Metadata Behavior: The Metadata behavior controls whether or not metadata is exposed to the outside world.
  4. Instance Behavior: The Instance behavior drives how many instances of the service will be available to process messages.
  5. Message Inspection: Message Inspection gives the service the ability to inspect all or parts of a message.
  6. 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.
  7. 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.
  8. 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.
  9. 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.

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:
  1. WS Security Channel: The WS Security channel implements the WS-Security specification, which enables message security.
  2. WS Reliable Messaging Channel: Guaranteed message delivery is provided by the WS Reliable Messaging channel.
  3. Encoders: Encoders let you pick from a number of encodings for the message.
  4. HTTP Channel: The HTTP channel tells the service that message delivery will take place via the HTTP protocol.
  5. TCP Channel: The TCP channel tells the service that message delivery will take place via the TCP protocol.
  6. Transaction Flow Channel: The Transaction Flow channel governs transacted message patterns.
  7. NamedPipe Channel: The NamedPipe channel enables inter-process communication.
  8. MSMQ (Microsoft Message Queuing) 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:
  1. 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.
  2. .EXE: WCF allows services to be run as executables (.EXE files).
  3. Windows Services: WCF allows services to be run as a Windows service.
  4. COM+: WCF allows services to be run as a COM+ application.

WCF Features
1.   Transactions
A transaction is a unit of work. A transaction ensures that everything within that transaction either succeeds as a whole or fails as whole.
WCF incorporates this same transactional processing into its communication. You as a developer can now group communications into transactions. On the enterprise level, this feature lets you execute transactional work across different platforms.
2.   Hosting
WCF hosting allows services to be hosted in a handful of different environments, such as Windows NT Services, Windows Forms, and console applications, and well as IIS (Internet Information Services) and Windows Activation Services (WAS).
Hosting a service in IIS has added benefits in that the service can take full advantage of many of the native IIS features. For example, IIS can control the starting and stopping of the service automatically.
3.   Security
Everything from messages to clients and servers get authenticated, and WCF has a feature that ensures messages aren’t messed with during transit. WCF includes message integrity and message confidentiality.
WCF also enables you to integrate your application into an existing security infrastructure, including those that extend beyond the standard Windows-only environments by using secure SOAP messages.
4.   Queuing
WCF provides queuing, allowing messages to be safely stored, providing a consistent state of communication. Queuing collects and stores sent messages from a sending application and forwards them on to the receiving application. This provides a safe and reliable message delivery mechanism.

No comments:

Post a Comment