Windows Communication Foundation (WCF)

WCF Layered Architecture.. The Complete Windows Communication Foundation (WCF) Developer Course 2023 [Videos].

Windows Communication Foundation (WCF) is a platform or a framework for creating and distributing connected applications. Built on top of the 2.0 .NET Framework CLR, the WCF is a set of classes that allows developers to build service-oriented applications.

WCF has a layered architecture that offers ample support for developing various distributed applications. The architecture is explained below in detail.


The contracts layer is just next to the application layer and contains information similar to that of a real-world contract that specifies the operation of a service and the kind of accessible information it will make. Contracts are basically of four types discussed below in brief −

  • Service contract − This contract provides information to the client as well as to the outer world about the offerings of the endpoint, and the protocols to be used in the communication process.

  • Data contract − The data exchanged by a service is defined by a data contract. Both the client and the service has to be in agreement with the data contract.

  • Message contract − A data contract is controlled by a message contract. It primarily does the customization of the type formatting of the SOAP message parameters. Here, it should be mentioned that WCF employs SOAP format for the purpose of communication. SOAP stands for Simple Object Access Protocol.

  • Policy and Binding − There are certain pre-conditions for communication with a service, and such conditions are defined by policy and binding contract. A client needs to follow this contract.

Service Runtime

The service runtime layer is just below the contracts layer. It specifies the various service behaviors that occur during runtime. There are many types of behaviors that can undergo configuration and come under the service runtime.

  • Throttling Behavior − Manages the number of messages processed.

  • Error Behavior − Defines the result of any internal service error occurrence.

  • Metadata Behavior − Specifies the availability of metadata to the outside world.

  • Instance Behavior − Defines the number of instances that needs to be created to make them available for the client.

  • Transaction Behavior − Enables a change in transaction state in case of any failure.

  • Dispatch Behavior − Controls the way by which a message gets processed by the infrastructure of WCF.

  • Concurrency Behavior − Controls the functions that run parallel during a client-server communication.

  • Parameter Filtering − Features the process of validation of parameters to a method before it gets invoked.


This layer, composed of several channels, mainly deals with the message content to be communicated between two endpoints. A set of channels form a channel stack and the two major types of channels that comprise the channel stack are the following ones −

  • Transport Channels − These channels are present at the bottom of a stack and are accountable for sending and receiving messages using transport protocols like HTTP, TCP, Peer-to-Peer, Named Pipes, and MSMQ.

  • Protocol Channels − Present at the top of a stack, these channels also known as layered channels, implement wire-level protocols by modifying messages.

Activation and Hosting

The last layer of WCF architecture is the place where services are actually hosted or can be executed for easy access by the client. This is done by various mechanisms discussed below in brief.

  • IIS − IIS stands for Internet Information Service. It offers a myriad of advantages using the HTTP protocol by a service. Here, it is not required to have the host code for activating the service code; instead, the service code gets activated automatically.

  • Windows Activation Service − This is popularly known as WAS and comes with IIS 7.0. Both HTTP and non-HTTP based communication is possible here by using TCP or Namedpipe protocols.

  • Self-hosting − This is a mechanism by which a WCF service gets self-hosted as a console application. This mechanism offers amazing flexibility in terms of choosing the desired protocols and setting own addressing scheme.

  • Windows Service − Hosting a WCF service with this mechanism is advantageous, as the services then remain activated and accessible to the client due to no runtime activation.

    At the heart of WCF is a layered architecture that supports a lot of the distributed application development styles. There are four major layers that provide developers a new service-oriented programming model. The following image shows the various layers and their components. 

    Layer 1:  Contracts

    WCF contracts are much like a contract that you and I would sign in real life. This contract or WCF contract contains information such as what a service does and the type of information it will make available. A WCF Contract is a collection of Operations that specifies what the Endpoint communicates to the outside world. There are four types of contracts.
    1. Data contract explicitly stipulates the data that will be exchanged by the service.
    2. Message contract controls the SOAP messages sent and received by the service.
    3. Service contract is what informs the clients and the rest of the outside world what the endpoint has to offer and communicate.
    4. Policy and Binding contracts specify important information such as security, protocol and other information.

    Layer 2:  Service Runtime

    This layer specifies and manages the behaviors of the service that occur during service operation.
    List of various behaviors managed by Service Runtime layer:
    1. Throttling Behavior determines the number of processed messages.
    2. Error Behavior specifies what action will be taken if an error occurs during service runtime.
    3. Metadata Behavior controls whether or not metadata is exposed to the outside world.
    4. Instance Behavior drives how many instances of the service will be available to process messages.
    5. Message Inspection gives the service the ability to inspect all or parts of a message.
    6. Transaction Behavior has the ability to rollback the transaction, if a process fails during the service runtime.
    7. Dispatch Behavior service determines how the message is to be handled and processed.
    8. Concurrency Behavior determines how each service, or instance of the service, handles threading.
    9. Parameter Filtering filters the message headers and executes preset actions based on the filter of the message headers.

    Layer 3:  Messaging

    This layer defines what formats and data exchange patterns can be used during service communication.
    Following lists the channels and components that the Messaging layer is composed of:
    1. WS Security Channel implements the WS-Security specification, which enables message security.
    2. WS Reliable Messaging Channel which provides guaranteed message delivery.
    3. Encoders let you pick from a number of encodings for the message.
    4. HTTP Channel tells the service that message delivery will take place via the HTTP protocol.
    5. TCP Channel tells the service that message delivery will take place via the TCP protocol.
    6. Transaction Flow Channel governs transacted message patterns.
    7. NamedPipe Channel enables inter-process communication.
    8. MSMQ Channel helps to use MSMQ.

    Layer 4:  Activation and Hosting

    This layer provides various 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. The following list details the hosting and activation options provided by this layer:
    1. 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.
    3. Windows Services, WCF allows services to be

See All

Comments (741 Comments)

Submit Your Comment

See All Posts

Related Posts

Windows Communication Foundation (WCF) / Blog

What is WCF?

WCF stands for Windows Communication Foundation. It is basically used to create a distributed and interoperable Application. WCF Applications came into the picture in .Net 3.0 Framework. This is a framework, which is used for creating Service oriented Applications. You can send the data asynchronously from one end point to another. I think you all know about Web Service and are thinking, if we already have Web Services and accessing on a remote basis then why did WCF come into picture?
22-Apr-2022 /50 /741

Windows Communication Foundation (WCF) / Blog

Major differences that exist between WCF and a Web service.

WCF (Windows Communication Foundation): WCF, as the name suggests, is a unified .NET framework that is used to develop service-oriented applications. It allows you to develop applications that can communicate using different communication mechanisms.
22-Apr-2022 /50 /741

Windows Communication Foundation (WCF) / Blog

Difference between WCF and Web API.

WCF is used to create a distributed and interoperable Applications. It provides a framework which is used for building service-oriented-connected applications for the transmission of the data as an asynchronous, from one service-point to other service-point. Previously known as Indigo and is a framework for building, configuring, and deploying network-distributed services.
22-Apr-2022 /50 /741