What is WCF?

Posted on 4/12/2008 @ 1:03 PM in #WCF by | Feedback | 13075 views

WCF stands for "Windows Communication Foundation".

It is that part of .NET 3.0, which is the newest coolest way of establishing communication between two pieces of executing computer code.

Now, we have had DDL, DCOM, Remoting, Web Services, WSE, .. why .. YET ANOTHER .. way of communication? Why oh why do I have to learn YET another thing?

Well, I hear ya.

WCF is fundamentally different from previous communication technologies. Another common "jargon-phrase" you will hear thrown around a lot is "SOA" or Service Oriented Architecture. Extremely simplified, think of SOA has different pieces of code/services running around the world and clients can make use of those services. These service hosts take care of internal complexities, and the communication infrastructure allows for things such as versioning and the communication infrastructure.

Thus, a big tenet of SOA is isolation. Let me explain with an example.

Say, you are consuming a web service, that accepts a zipcode, and returns you a weather forecast. All you, the client, ever cares about is .. the zipcode (input), and the forecast (output). Beyond the input/output .. or request/response .. the service host .. never talks to the client. There is an isolation between the client and server, and they interoperate on only what they had agreed to interoperate upon, i.e. the contract. So, this brings me to the first important piece in WCF, "The Contract".

Contract: This is the heart of your service - what does your service do!

In WCF, a contract is usually implemented as an interface decorated by the [ServiceContractAttribute]. For instance, in this particular case, your contract would look like this -

   1: [ServiceContract]
   2: public interface IWeatherService
   3: {
   4:     [OperationContract]
   5:     public WeatherForecast GetForeCast(int zipCode);
   6: }

But is a contract all I need? Well no .. because I need to know atleast 3 peices of information before I can use such a service -

  • Where can I find this service - The Address.
  • What protocol will I use in using this service - The Binding.
  • And of course the contract - when I know where the service is (address), and how I will technologically speaking use it (binding) - what the heck will I do with it .. the Contract.

So, in WCF, you have ABC's -

The Basics

Address: Address is where your service can be found. Usually in the format of scheme://domaon[:port]/path. Example http://localhost:8080/MyService

Binding: A binding refers to specific protocols used by a particular endpoint. Example, http, tcp, msmq etc.

Contract: This is the heart of your service - what does your service do!

These 3 together, form an "EndPoint".

EndPoint: EndPoint is how a ServiceHost, exposes a service, so clients can invoke it's operations defined in the contract. (Read that again!).  So, how is an EndPoint different from an Address? An EndPoint have 3 peices - Address, Binding, and Contract.

Now, note that in the contract I showed above, I am using a return type called "WeatherForecast". The "WeatherForecast" is a class I wrote, that represents a business object which lets me conveniently hold the details of the data I am accepting or sending. This along with all details of the endpoint constitute, the "MetaData" for the service.

Also, for "WeatherForecast" to go over the wire, it must be Serializable. Being Serializable means, the object can be hydrated, dehydradted from a stream/bunch of bytes, into a living class instance. Thus, if the human body was serializable, teleportation like Star Wars shows us all the time, would be possible. The business object "Human Body" would be dehydrated into "information" - sent over a communication channel(s), and then rehydrated at the other side - to produce a human being on the other side. Sure beats my commute.

And given the MetaData for a service, a consumer of the service, can now create a Proxy - which is an empty shell, or a type, that exposes all details of the service.

Proxies: A client communicates with a host using a proxy. A proxy is an empty type that exposes all operations in a service contract, and hides serialization/sending over wire details. A single proxy, uses a single endpoint.

Finally, the client, and the host, talk to each other through various channels. And around these channels, you may have various behaviors associated with the service.

Channels: Channels, is what a message goes through when it goes between a client and a host. Usually you have multiple stacked channels.

Behavior: Behaviors modify the message as they flow through a channel stack. A good example of a behavior is authorization.

So .. overall ..

You have a host, and a client, both agree on a contract. The host exposes EndPoints which are a combination of Address, Binding and Contract. The client uses a proxy, that is tied to a particular endpoint - thus tied to a particular contract. And the actual communication related details are abstracted in Channels and Behaviors.

That one line above, summarizes WCF.

So, what makes WCF different?

  • You first think of the Contract - What am I trying to get done!?
  • Then you think of where will I host it, and what technology will I use to host it.
  • Then you worry about the nitty gritties such as authentication etc.

For the very first time, you have a communication technology, that lets you first focus on what you're trying to get done, and worry about communication later.

I say, time to write a quick application huh?

Sound off but keep it civil:

Older comments..

On 4/12/2008 6:04:11 PM Leniel Macaferi said ..
Hi Sahil,

Great post explaining the basics of WCF. Keep up the good work!

I was going to read this post http://blah.winsmarts.com/2008-4-Writing_the_WCF_Hello_World_App.aspx but then I followed your advice and started with this one.

Leniel Macaferi

On 4/12/2008 9:08:09 PM Sahil Malik said ..
Hey Leniel :),

I checked out your blog man. Dude you're like some hifi scholar. Please feel free to shed some words of wisdom here too .. ok? :)


On 4/12/2008 9:09:12 PM Tasneem said ..
You do have a knack of explaining jargons in simple words. I am looking forward to see examples using different type of bindings especially MSMQ.

On 4/12/2008 11:29:13 PM Sahil Malik said ..
Thanks Tasneem .. see I explain stuff only I understand myself .. LOL, so it becomes simple.

Look at me .. as an MSDN translator.

On 5/6/2008 9:51:04 AM Patrice RAUCQ said ..
Hi Sahil,

Your explanations are very clear and usefull. Using the same talent could you explain what can decide the developer when he/she has to choose a binding. What makes the difference between TCP, HTTP, MSMQ, etc. if all technologies are available in the production environment ?

Thanks in advance,


On 5/6/2008 9:52:08 AM Sahil Malik said ..
Thanks Patrice - I'll do that shortly. Had a few busy days, but should be able to get back to this serious in 2 weeks.

On 5/28/2008 3:38:07 AM Torben Bach said ..
Excelent post - short, clear and to the point :-)

On 7/3/2008 2:03:20 AM Aarti said ..
Hi Sahil,

I have to learn WCF for some project requirement. When i started going thru msdn, I found it so boring and dry and complicated...and what not..i had slowly started losing interest in the technology itself..:(

But after reading ur post i understood the basics very quickly..such free and simple lingo...

Very nice article..!!

On 8/12/2008 12:02:08 PM Matt said ..
Great post I was able to figure out the basics first read. I have to make one point, there are no transporters in Star Wars that would have to be Star Trek :).

On 8/12/2008 1:05:38 PM Sahil Malik said ..
Matt - I am the most non-geek nerd you'll meet. I've never even seen the star*.* movies.

On 8/22/2008 1:32:47 PM Arvinth Chandramouli said ..
I am trying to design an n-tier app. I am trying to design a data access layer and want to remote the business objects. Please shed your opinion about using strongly typed datasets vs creating my own data access code for business objects and remoting vs WCF. thanks very much.

On 9/2/2008 8:34:01 PM Lloyd Phillips said ..
Great article, you certainly do have a knack for putting things into layman's terms. I can't stand reading MSN they just go on with geeky jargon rather than just saying it how it is in a few sentances. I've struggled to understand the concepts of WCF when researching it for the last few weeks. I've been looking at creating an AJAX based site using the Dojo toolkit. I need to connect much of the display to an asp.net back end but really wanted to do it via JSON as XML is so much more bloated. Having seen some bits on the web I thought WCF would be a good option for this as I can make AJAX calls and get JSON returned. It's looking like I might be correct. I'd LOVE to se some examples from you on creating a project that returns JSON via WCF. Keep these articles coming!

On 12/6/2008 7:04:03 AM waqar qureshi said ..

ur article is good enough, but i am facing a problem for the last 7 days and no body is able to help me.

i wanna create wcf services for our company website but it works fine on localhost but i am not able to deploy on our website through your example. Even if i publish my wcf service on our website through other methods, i am not able to access it from new asp.net project. what are the changes i have to make in web.config so that i am able to deploy and if already published, to access it.

ur help will be highly appreciated.

On 4/1/2009 4:18:21 PM WarNov said ..
Hey Sahil,

They in MSDN must include an introduction like this for every theme they have there.

It is true, that I spent like two hours reading their WCF Introduction, lost in a million of hyperlinks and never got an idea as clear as the one I got reading your post.


On 4/1/2009 4:54:41 PM Sahil Malik said ..
Thank you Warnov. I will never write for MSDN Mag. It seems like you need to have a "friend" there to be able to write for them. And I don't think their "friends" do a good job. Many of their articles I feel are too arcane and more complex than necessary .. simply because the author never took the time to digest the information before presenting it to the reader. Frankly, a good article is what takes a complex concept and makes it simple. MSDN articles seem to show off their complexity. WTF!


On 1/5/2010 1:03:33 AM Sarnendu De said ..
Good article,WCF is clearly explained for beginner but not cleared why we need WCF instead of Remoting, Web Services.It will be helpful if you can clear.


Sarnendu De

On 2/24/2010 1:58:23 AM Deepak Kokate said ..
Thanx for this post. It cleared my understanding about WCF

On 3/27/2010 10:23:25 PM hims said ..
Hi Sahil ..I am working on SharePoint Technologies .. in its SP2010 version microsoft has included WCF widely .. so I was looking for some starting point to understand basic concept .. this has clarify the basic stuff with in few min.. Thanks a lot.. keep good posting like this..

On 5/27/2010 4:15:24 PM Sahil Malik said ..

On 8/6/2010 1:47:11 PM Xavier said ..
I'm beginning to learn WCF. This was one excellent introduction to the subject. There are some minor spelling and grammatical errors, though it doesn't affect the clarity of presentation. I would still recommend this simple writing, over the jargon filled MSDN articles. One question that popped up in my mind was, "So, how is WCF different from .NET remoting or Java RMI" ?

On 11/29/2010 1:17:01 PM misc said ..
It's Star Trek man.. : ) Star Wars didn't have beaming--teleport--technology.

On 12/17/2010 6:10:25 AM Monalisa said ..
I read many articles on WCF before. I lost interest while reading the articles and i didnot get the basic idea behind WCF.I got the concepts now.Thanks a lot Sir!!!

On 2/27/2011 12:31:02 AM Novice said ..
Woww !! What clarity man !! May industry be blessed with..more such clear articles :-)

On 3/12/2011 2:52:42 PM dino said ..
Hey Sahil,

well what else to say, the comments above speak for them selves.

Aside that you screwed it up a bit with the Star Wars, I can only say BRAVO!!! :)

Keep the great articles comming PLEASSSSEEEEE!


On 3/15/2011 2:03:02 AM Maruf Hassan said ..
Now I understand what is WCF, thanks

On 3/25/2011 3:12:02 PM Ramesh Kadirisani said ..

I was just curious to know how WCF works and your article explained the details in the most simple way.

Thanks a lot!!

Ramesh K.

On 4/20/2011 4:59:29 AM Cindrella said ..

On 5/6/2011 9:24:38 AM Salman Khan said ..
Great post !!

On 5/27/2011 4:35:29 PM Abhinav said ..
Start charging for MSDN translation and I will be your first client.



On 5/28/2011 7:04:48 PM Nervdeshwar said ..
Great job Sahil. You have this talent man !. You made it so simplified. Keep up the good job. If I want to follow you were can I?

On 8/17/2011 2:25:29 AM Abhay Bhardwaj said ..
I am new to WCF and found your post really helping.

Good Post.

Thanks !

On 11/6/2011 1:21:39 PM Francis Balafa said ..
The most clear explanation i've read so far!!

Thank you

On 2/24/2012 3:34:01 AM Ahmad said ..
Thanks for the clear explanation .. AWESOME :)

On 5/21/2012 1:49:29 PM Deepak said ..
Stupendous! I will remember the analogies for the rest of my life or at least till Alzheimer's kicks in :)

On 5/28/2012 6:55:15 AM hanaa said ..

really that is great article in WCF topic

Thanks alot

On 7/5/2012 6:00:01 AM Pradeep said ..
Hi Sahil,

Thanks for the great article on WCF in very simple words and that's the specialty. Please keep bringing good articles for beginners.



On 7/13/2012 3:58:19 AM robby said ..
Wow, what a REMARKABLE and simple tutorial on Web Services and WCF. There's a lot of verbose content which is just useless and becomes mundane after the very first line. You have done an INCREDIBLE job with explaining this. Well done and keep up the great work. Maybe you can place some more tutorials on other ASP Dot Net concepts.

On 9/5/2012 2:45:35 AM mahesh said ..
gr8 work dude,