WCF Series - Introduction to WCF


In this article we are going to see an introduction to Windows Communication Foundation.

WCF is a unified programming model for building service oriented distributed applications .

Lets go down the History of Distributed applications . The Monolithic applications gave way to applications built with components using COM ( Component Object Model ) . Monolithic applications would mean where everything exists with a single exe or a application . Using COM you could create components which would do particular tasks and COM would make these applications available to you .

This was good for the Desktop applications . But what about the Web world . So Desktop COM make way for Distributed COM .

So now COM components could be hosted on the Server and your application could access this COM components .

DCOM further evolved into COM+ and intergrated with the Transaction Server . So all your datalogic and Business log would now run on a Central Server and you could now have transactions supported as well.

And then came .NET , and rather than completely rewrite the Business Logic . The .Net components can now use Enterprise Services to Leverage COM+.

Another option to build distributed applications was Remoting. .NET Remoting consists of a client and remote objects hosted on a server .

Client can access remote objects as if they are local .

Enterprise Services and .NET Remoting require client , components and data to be on the same network . But what happends when that is not the case . What happens when you client and data to be accessed by the Client are not in the same netwrok .

Web Services Solves this problem . Web Services enable you to pass data as XML over Internet .

Now the Client and Server to pass the XML back and forth both Client and Server need to agree upon how the xml looks like . That's where SOAP comes in .

Simple Object Access Protocol defines structure of XML messages clients and services pass .

Visual Studio helps us create and comsume Web Services easily without much trouble . So this approach of Building Distributed applications is called Service orientation .

A Service is a program that performs a task and that you can interact with through well defined messages .

In other words we can say that a Service Oriented application consists of loosely coupled services that communicate through messages and contracts.

Messages are the actual messages that go back and forth and contracts are basically the interfaces that define what the service will do .

They are Loosely coupled because the Client does not instantiate the Service .
So this is a major difference between a Service oriented architecture or say a COM component model where the Client would have to instantiate the Server Class .

In the Service Oriented Architecture the Client does not instantiate the Service , instead it just passes the method .

So there is a Shift from remotely invoking components to passing messages between services .

Principles of Service Orientation :

  1. Boundaries are explicit i.e. Services communicate by sending messages across the boundary. All communication occurs through the messages .
  2. Services are Autonomous i.e. You can build , manage and version services independently . You can change a service without affecting Clients as long as clients can continue sending and receiving the messages .
  3. Services share Contract and Schema

    Contracts describe the message services can send and receive .

    Schemas define how the client and services construct the messages they exchange .
     
  4. Compatibility is policy based .

Services can define the circumstances under which clients can communicate with them.

So at this point you must be getting a question are Web Services Service Oriented . The answer is Yes . So we already have a Service Oriented technology working great for us . So why go for WCF . Why do we developers have to learn another technology.

Whats wrong with what we have .

Too many ways to create a distributed applications . Too many options are not good as well . WebServices ( SOA ) and Enterprise Services , .NET Remoting ( not SOA).

Which should you use and when
Do you need interoperability ?
Are you going over the Internet or over TCP ?
Are you accessing services internally or externally ?

In simple terms WCF is a one word solution to all our problems .

WCF comes to the Rescue :

  • WCF Provides a Unified Programming Model for building Service oriented applications .
  • One model whether communication is internal or external .
  • Same service can be exposed over multiple protocols without duplicating effort or switching technologies .

If you had to expose the WCF Externally you would expose it on HTTP and if you had to expose the WCF Internally you could do it on TCP and you could expose both on same time as well.

Lets also discuss the most common question everyone asks when starting with WCF.

WCF Vs WebServices :

I promise that there is gone be only one Winner .

WCF Has the following features over Web Services :

  • Send messages via not only HTTP , but also TCP and many other protocols .
  • Send messages using formats other than SOAP for example REST( Representational State Transfer ) and Plain Old XML (POX).
  • Host Service on hosts other than a Web Server .
  • Built in support for transactions and reliable sessions where as for WebServices these would be a add on .
  • Build in support for managing configurations , tracing and logging messages.

In the next post we will start creating our first WCF Service .

Up Next
    Ebook Download
    View all
    Learn
    View all