This post is part of a series of WCF posts. The following list will updated and published with each post:

  1. In Depth Windows Communication Foundation (Part 1) - Introduction & WCF Architecture
  2. In Depth Windows Communication Foundation (Part 2) - Address, Binding & Contract
  3. In Depth Windows Communication Foundation (Part 3) - Our first Service and Client
  4. ...

In my previous WCF post, I gave you an introduction and a architectural overview of WCF. It already contained lots of concepts which on first hand might seem complex and unknown. In this post I'd like to explain the WCF mantra a bit more.


The following picture gives a basic understanding of client - service messaging:

wcfabc.png

You can find this ABC everywhere on the Internet, let me just summarize it for you:

  • "A" stands for Address: Where is the service?
  • "B" stands for Binding: How do I talk to the service?
  • "C" stands for Contract: What can the service do for me?

    And so an endpoints is in fact the combination of an Address, a Binding and a Contract.

    Remember this:

    • The Service can expose itself on multiple endpoints (on different addresses using different bindings). What's a binding? Read on...
    • The Client can only reference a service contract on one endpoint conforming the binding used on that endpoint. (of course it can reference other services on other endpoints)

    An example of an ABC configuration :

     

    image

     

     

     

    You can see the Address, the Binding, and the Contract described in the endpoint element.

    Here is a graphical representation of a service endpoint:

    A ServiceEndpoint contains an EndpointAddress (where?), a Binding(how?) and a ContractDescription(what?).

    Address

    "Provides a unique network address that a client uses to communicate with a service endpoint." (http://msdn2.microsoft.com/en-us/library/system.servicemodel.endpointaddress.aspx)

    Binding

    A binding "represents a collection of binding elements, each of which describes an aspect of how an endpoint communicates with other endpoints and that are built, consistently, into a channel factory on the client and into a channel listener on the service. A binding contains a collection of binding elements that correspond to protocol channels, transport channels, and message encoders. There can be any number of binding elements for protocol channels but one and only one binding element for each the transport and message encoder." (http://msdn2.microsoft.com/en-us/library/system.servicemodel.channels.binding.aspx)

    There is a lot to say about bindings. They make all sorts of transport, security and interoperability happen. WCF provides system-defined bindings and its possible to extend WCF with custom bindings.
    First lets take a look what a binding looks like:

    So a binding as a Name, a Namespace and a set of BindingElements. A BindingElement is an abstraction of a Channel... and what is a channel?

    (There is a nice mini book about WCF Channels available at
    http://wcf.netfx3.com/files/folders/product_team/entry3550.aspx)

  • Quotes from "Channel Model Overview":

    A Binding... "is a layered communication stack with one or more channels that process messages. At the bottom of the stack is a transport channel that is responsible for adapting the channel stack to the underlying transport (for example, TCP, HTTP, SMTP and other types of transport.). Channels provide a low-level programming model for sending and receiving messages. This programming model relies on several interfaces and other types collectively known as the WCF channel model."

    So a channel is a shackle in the Binding communication chain and allowes us to influence to message passing through.. Let's compare it with a TCP stack:

    Channel Model

    "First, the similarities: In both cases, each layer of the stack provides some abstraction of the world below that layer and exposed that abstraction only to the layer directly above it. Each layer uses the abstraction of only the layer directly below it. Also in both cases, when two stacks communicate, each layer communicates with the corresponding layer in the other stack, for example, the IP layer communicates with the IP layer and the TCP layer with the TCP layer, and so on.

    Now, the differences: While the TCP stack was designed to provide an abstraction of the physical network, the channel stack is designed to provide an abstraction of not only how the message is delivered, that is, the transport, but also other features such as what is in the message or what protocol is used for communication, including the transport "

    "Messages flow through the communication stack as Message objects. As shown in figure above, the bottom channel is called a transport channel. It is the channel that is responsible for sending and receiving messages to and from other parties. This includes the responsibility of transforming the Message object to and from the format used to communicate with other parties. Above the transport channel there can be any number of protocol channels each responsible for providing a communication function such as reliable delivery guarantees."

    I already mentioned it, WCF gives us a set of system-defined Bindings made up by system defined BindingElements. All of these BindingElements can in a way be reused in custom Bindings and of course we can write our own BindingElements/Channels to make up new Bindings!
    A complete list of standard WCF bindings (including the new 3.5 ones) is given here.

    Wow.. does your developers heart beats twice as fast now? :)  This model provides us endless extensiblity options! and believe me, this is just the beginning, because 'extensibility' is WCF's middle name!

    All services out there implement some communication pattern... Often they are called Message Exchange Pattern's (MEP's) but within WCF documentation they are often refered to as Shapes.
    You propably recognize some of them :

    • One-Way - the client is the initiator and messages go from client to service.
    • Request-Response  - the client is the initiator and sends a message after which a response is sent back
    • Duplex - both client and service can be the initiator and messages flow back and forward.

    A channel always implements one or more of these Shape interfaces: IInputChannel/IOutputChannel/IDuplexChannel and IReplyChannel/IRequestChannel for request/response pattern.

    Contract

    "A WCF Contract is a collection of Operations that specifies what the Endpoint communicates to the outside world." (http://msdn2.microsoft.com/en-us/library/aa480210.aspx)

    Remember that SOA tenet "Services share schema and contract, not class or type" Don gave us in my previous post?  This is the service contract. This way, nice interoperable messaging can be established between all sorts of communication stacks based on different plantform technologies. These stacks of course have to comply to some mutual standards; for example SOAP, WSDl and WS-* standards. I'll write more about those subjects later..

    A ServiceContract might look like this:

    1 [ServiceContract]
    2 public interface IService1
    3 {
    4 [OperationContract]
    5 string GetData(int value);
    6
    7 [OperationContract]
    8 CompositeType GetDataUsingDataContract(CompositeType composite);
    9 }

    (pictures from http://msdn2.microsoft.com/en-us/library/aa480210.aspx)

    Next time, I'll start working with a code example which I'll use throughout all next posts.

    More to read in my next post in this series:

    In Depth Windows Communication Foundation (Part 3) - Our first Service and Client

     


    Posted in: .NET 3.0 , .NET 3.5 , WCF  Tags:

    Be the first to rate this post

    • Currently 0/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5

    This post is part of a series of WCF posts. The following list will updated and published with each post:

    1. In Depth Windows Communication Foundation (Part 1) - Introduction & WCF Architecture
    2. In Depth Windows Communication Foundation (Part 2) - Address, Binding & Contract
    3. In Depth Windows Communication Foundation (Part 3) - Our first Service and Client
    4. ...

    Introduction

    At my current assignment, the last couple of months I've worked a lot with WCF.  During this time I had many challenges to cope with and it seems to me that the WCF learning curve can be rather steep.
    There are a lot of books and blogs out there, describing different WCF subjects and I've used a lot of them.
    As a start on this website, I have now planned a series of (more or less) 17 posts about WCF. It will begin with covering the basics but will advance pretty soon to more complex parts of using the WCF framework.
    I'll try to get rather fast to the more interesting advanced scenario's, but I think it is important to also give the basic information for those who have not yet looked into WCF (at all).
    I will use information and pictures found on other web sites and I will try to always give credits to the original owners... so please give me a hint when I've forgotten about you :)
    In this first post I'd like to list the books, and URL's that I found useful and I'll describe the general architecture of WCF.
    (I'll update these lists as frequently as possible)

    I think the following books are of great assistance while exploring WCF:

    Programming WCF Services - Juval Lowy

    Programming WCF Services (Programming)

    Inside Windows Communication Foundation

    Inside Windows  Communication Foundation (Pro Developer)

    Further, I recommend to read the following blogs :

    WCF Architecture

    Overview

    In October 2003 the first official anouncement about "Indigo", the new communication platform now known as WCF, was done by Don Box on the Professional Developers Conference in Los Angeles. It was supposed to be one of the four pillars (the other pillars are: Avalon-now knowns as Windows Presentation Foundation WPF-,    WinFS-the revolutionary new file system and     WinFX-now known as the .NET framework 3.0) of the new "Longhorn" operation system.


    In 2004 Don Box published an article on MSDN called "A Guide to developing and Running Connected Systems with Indigo" in which he explained the principles of WCF with the help of four SOA tenets:

    • Boundaries are explicit
    • Services are autonomous
    • Services share schema and contract, not class or type
    • Service compatability is based upon policy

    These tenets are nicely described by the BPM Institute.

    So WCF is build from the ground up with these SOA tenets and SOA vision in mind.. what does it look like?

    Because a picture says more than a 0x3E8 words, the following picture gives a clear view of the WCF architecture.
    The 'Contracts' and 'Service runtime' parts can be seen as the service model;
    the 'Messaging' part can be seen as the channel model.

    The WCF Architecture

    Windows Communication Foundation Architecture

    The individual parts are explained on the Microsoft site:

    • Contracts

    "Contracts define various aspects of the message system. The data contract describes every parameter that makes up every message that a service can create or consume"

    "The message contract defines specific message parts using SOAP protocols, and allows finer-grained control over parts of the message, when interoperability demands such precision. The service contract specifies the actual method signatures of the service, and is distributed as an interface in one of the supported programming languages, such as Visual Basic or Visual C#."

    "Policies and bindings stipulate the conditions required to communicate with a service. For example, the binding must (at a minimum) specify the transport used (for example, HTTP or TCP), and an encoding. Policies include security requirements and other conditions that must be met to communicate with a service."

    • Service Runtime

    "The service runtime layer contains the behaviors that occur only during the actual operation of the service, that is, the runtime behaviors of the service. Throttling controls how many messages are processed, which can be varied if the demand for the service grows to a preset limit. An error behavior specifies what occurs when an internal error occurs on the service, for example, by controlling what information is communicated to the client. (Too much information can give a malicious user an advantage in mounting an attack.) Metadata behavior governs how and whether metadata is made available to the outside world. Instance behavior specifies how many instances of the service can be run (for example, a singleton specifies only one instance to process all messages). Transaction behavior enables the rollback of transacted operations if a failure occurs. Dispatch behavior is the control of how a message is processed by the WCF infrastructure.

    Extensibility enables customization of runtime processes. For example, message inspection is the facility to inspect parts of a message, and parameter filtering enables preset actions to occur based on filters acting on message headers."

    • Messaging

    "The messaging layer is composed of channels. A channel is a component that processes a message in some way, for example, by authenticating a message. A set of channels is also known as a channel stack. Channels operate on messages and message headers. This is different from the service runtime layer, which is primarily concerned about processing the contents of message bodies. There are two types of channels: transport channels and protocol channels. Transport channels read and write messages from the network (or some other communication point with the outside world). Some transports use an encoder to convert messages (which are represented as XML Infosets) to and from the byte stream representation used by the network. Examples of transports are HTTP, named pipes, TCP, and MSMQ. Examples of encodings are XML and optimized binary.

    Protocol channels implement message processing protocols, often by reading or writing additional headers to the message."

    • Activation and Hosting

    "In its final form, a service is a program. Like other programs, a service must be run in an executable. This is known as a self-hosted service.

    Services can also be hosted, or run in an executable managed by an external agent, such as IIS or Windows Activation Service (WAS). "

    These quotes contains lots of concepts that will be explained in later posts.. for now, try to get the broad pictrure of WCF... details will follow soon..

    Lots of developers who build services and clients in .NET will only interact with the service model. It's the WCF programming model when using standard WCF functionality and its an abstraction of the underlying Channel Model. But, if you need to support advanced scenario's like custom interoperability, a different transport protocol or your custom serializer you will need to dive deeper into the WCF architecture and more particular its extensibility points.

    More in the next WCF post:

    In Depth Windows Communication Foundation (Part 2) - Address, Binding & Contract


    Posted in: .NET 3.0 , .NET 3.5 , WCF  Tags:

    Currently rated 2.0 by 1 people

    • Currently 2/5 Stars.
    • 1
    • 2
    • 3
    • 4
    • 5

    Page List

      Calendar

      «  July 2010  »
      MoTuWeThFrSaSu
      2829301234
      567891011
      12131415161718
      19202122232425
      2627282930311
      2345678
      View posts in large calendar

      Recent Comments

      Feedburner Statistics 7/29/2010
      0 Readers ~ 0 hits ~ 0 reach

      Disclaimer
      The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

      © Copyright 2010 Inwit.nl