Learning Center
Plans & pricing Sign in
Sign Out

WCF 1 Part


 1) Home
 2) Getting Started
     i) Introduction to WCF
     ii) Development Tools
     iii) Difference between WCF and Web service
 3) Books
 4) Fundamental
     i) EndPoint
     ii) Binding and Behavior
     iii) Contracts and Service Host
     iv) Message and Channel
     v) Client and Metadata
 5) WCF Architecture
 6) WCF Hosting
     i) IIS Hosting
     ii) Self Hosting
     iii) WAS Hosting
     iv) Windows Service Hosting
 7) WCF Binding
     i) Bindings and Channel Stacks
     ii) Types of Binding
     iii) Binding configuration
 8) Metadata Exchange
     i) HTTP_GET Enabled Metadata
     ii) Metadata Exchange Endpoint
 9) Contracts
     i) Service Contract
     ii) Data Contract
     iii) Message Contract
              a) MessageHeaderArray
              b) Message Contract Properties
     iv) Fault Contract
 10) Instance Management
     i) Per-Call Service
     ii) Per-Session Service
     iii) Singleton Service
 11) Instance Deactivation
 12) Durable Service
     i) How to Create Durable Service
13) Throttling
14) Operations
    i) Request-Reply
    ii) One-Way
    iii) Callback Service
               a) Create Callback Service
15) Events
16) Transfer mode
    i) Streaming
17) Transaction
      i) Two-Phase Committed Protocol
      ii) Transaction Propagation
      iii) Transaction Protocols
18) Exception in Silverlight
19) Custom Message Header
20) Introduction to WCF 4.0
Welcome to the WCF Tutorial

Welcome to WCF Tutorial about WCF tutorial. This tutorial will explain about WCF concepts, creating
new service and lot more things in WCF. This is great network distributed system developed by
Microsoft for communication between applications.

Getting Started
Welcome to the world of windows communication foundation. This section you will learn what is WCF
and how it is differ from web service. Tools require setting up the environment for WCF development
and great books on WCF also mention here.

       Introduction to WCF
       Development Tools
       Difference between WCF and Web service

Introduction to WCF
Windows Communication Foundation (Code named Indigo) is a programming platform and runtime
system for building, configuring and deploying network-distributed services. It is the latest service
oriented technology; Interoperability is the fundamental characteristics of WCF. It is unified
programming model provided in .Net Framework 3.0. WCF is a combined features of Web Service,
Remoting, MSMQ and COM+. WCF provides a common platform for all .NET communication.
Below figures shows the different technology combined to form WCF.


    1. WCF is interoperable with other services when compared to .Net Remoting, where the client
       and service have to be .Net.
    2. WCF services provide better reliability and security in compared to ASMX web services.
    3. In WCF, there is no need to make much change in code for implementing the security model and
       changing the binding. Small changes in the configuration will make your requirements.
    4. WCF has integrated logging mechanism, changing the configuration file settings will provide this
       functionality. In other technology developer has to write the code.


Making right design for your requirement is little bit difficult. I will try to help you on solving these
difficulties in the following article.
Development Tools
WCF application can be developed by the Microsoft Visual Studio. Visual studio is available at
different edition. You can use Visual Studio 2008 Expression edition for the development.

Visual Studio 2008 SDK 1.1

Microsoft Visual Studio 2008

Microsoft Visual studio 2008 provides new features for WCF compared to Visual Studio 2005.
These are the new features added to VS 2008.

   1. Multi-targeting

       You can create application in different framework like Framework 2.0, 3.0 and 3.5

   2. Default template is available for WCF
3. WCF - Test Client tools for testing the WCF service.

    Microsoft provides inbuilt application to test the WCF application. This can be done by
    opening the Visual Studio command prompt and type the wcfClient Serviceurl shows
    below. This will help the developer to test the service before creating the client
   4. WCF services can be debugged now in Visual Studio 2008. Wcfsvchost.exe will do it for
      you because service will be self hosted when you start debugging.

Difference between WCF and Web service
Web service is a part of WCF. WCF offers much more flexibility and portability to develop a
service when comparing to web service. Still we are having more advantages over Web service,
following table provides detailed difference between them.

  Features                   Web Service                                     WCF

                                                        It can be hosted in IIS, windows activation
Hosting       It can be hosted in IIS
                                                        service, Self-hosting, Windows service

              [WebService] attribute has to be added to [ServiceContraact] attribute has to be added
              the class                                 to the class

Model         [WebMethod] attribute represents the      [OperationContract] attribute represents the
               method exposed to client                      method exposed to client

               One-way, Request- Response are the
                                                             One-Way, Request-Response, Duplex are
Operation      different operations supported in web
                                                             different type of operations supported in WCF

               System.Xml.serialization name space is        System.Runtime.Serialization namespace is
               used for serialization                        used for serialization

               XML 1.0, MTOM(Message Transmission
Encoding                                             XML 1.0, MTOM, Binary, Custom
               Optimization Mechanism), DIME, Custom

               Can be accessed through HTTP, TCP,            Can be accessed through HTTP, TCP, Named
               Custom                                        pipes, MSMQ,P2P, Custom

Protocols      Security                                      Security, Reliable messaging, Transactions

Programming WCF Services, 2nd Edition

Programming WCF Services will teach you how to design and develop SOA-WCF-based applications. You will
need to be an experienced developer who has a fair understanding of .NET and C# 2.0. A couple of points about
Programming WCF Services, first, this isn't a beginner’s book; the author dives down into advanced material in
spots almost without notice. If you want to become proficient using WCF, you will be buying this book
eventually. You will find that this book will become both a reference as well as well as a guide.

Author: Juval Lowy

ISBN: 978-0-596-52130-1
Wrox-Professional WCF Programming

This book is very good for beginners. This book covers all the topics in WCF in general. I will recommend this
book, for initial stage of learning.

Author: Scott Klein

ISBN: 9780470089842

Microsoft Windows Communication Foundation Step by Step

Covering the concepts and details necessary to enable you to build connected solutions, this book offers hands-
on guidance for creating the Web services you need to implement robust business applications for Windows.
Teach yourself the essentials of Windows Communication Foundation-one step at a time. With this practical
tutorial, you get hands-on guidance for creating the Web services you need to implement robust business
applications for Windows.

Author: John Sharp

ISBN: 9780735623361
Pro WCF: Practical Microsoft SOA Implementation Book Description

This is also a very good book. The book covers all the WCF topics in depth while using a lot of examples schemas
and screenshots. This is a great book about how to develop WCF services. I really recommend this book, but I
like juval's more.

Author: Chris Peiris, Dennis Mulder, Shawn Cicoria,

ISBN: 1590597028

Microsoft Windows Communication Foundation: Hands-on

You will gain a comprehensive understanding of how to apply the Windows Communication Foundation to
almost any distributed computing problem, from enterprise scale to peer-to-peer. Most importantly, after
reading the book and working through the examples, you will actually have considerable experience using WCF,
because the book takes you through the steps of actually building Windows Communication Foundation

Author: Craig McMurtry

ISBN: 0672328771
Learning WCF

This is also one of the nice books from O'Relliy. One of my great architects also recommends this book.

Author: Michele Leroux Bustamante

ISBN: 978-0-596-10162-6

WCF Fundamental
In this part of tutorial you are going to learn about some fundamental concepts in WCF. These
concepts and terms will be used throughout this tutorial.

       End Point
       Bindings and Behavior
       Contracts and Service host
       Message and Channel
       WCF client and Metadata

WCF Service is a program that exposes a collection of Endpoints. Each Endpoint is a portal for
communicating with the world.

All the WCF communications are take place through end point. End point consists of three

Basically URL specifies where this WCF service is hosted .Client will use this url to connect to the
service. e.g.



Binding will describes how client will communicate with service. There are different protocols
available for the WCF to communicate to the Client. You can mention the protocol type based
on your requirements.

A binding has several characteristics, including the following:

         Transport -Defines the base protocol to be used like HTTP, Named Pipes, TCP, and MSMQ are
          some type of protocols.
         Encoding (Optional) - Three types of encoding are available-Text, Binary, or Message
          Transmission Optimization Mechanism (MTOM). MTOM is an interoperable message format
          that allows the effective transmission of attachments or large messages (greater than 64K).
         Protocol(Optional) - Defines information to be used in the binding such as Security, transaction
          or reliable messaging capability

The following table gives some list of protocols supported by WCF binding.

           Binding                                            Description

BasicHttpBinding             Basic Web service communication. No security by default

WSHttpBinding                Web services with WS-* support. Supports transactions

WSDualHttpBinding            Web services with duplex contract and transaction support

WSFederationHttpBinding Web services with federated security. Supports transactions

MsmqIntegrationBinding Communication directly with MSMQ applications. Supports transactions

                             Communication between WCF applications by using queuing. Supports

                             Communication between WCF applications on same computer. Supports
                             duplex contracts and transactions
                          Communication between computers across peer-to-peer services. Supports
                          duplex contracts

                          Communication between WCF applications across computers. Supports
                          duplex contracts and transactions


Collection of operation that specifies what the endpoint will communicate with outside world.
Usually name of the Interface will be mentioned in the Contract, so the client application will be
aware of the operations which are exposed to the client. Each operation is a simple exchange
pattern such as one-way, duplex and request/reply.

Below figure illustrate the functions of Endpoint


Endpoints will be mentioned in the web.config file on the created service.

   <service name="MathService"
     address="http://localhost:8090/MyService/MathService.svc" contract="IMathService"
    <behavior name="MathServiceBehavior">
     <serviceMetadata httpGetEnabled="True"/>
     <serviceDebug includeExceptionDetailInFaults="true" />

Binding and Behavior

Simple definition for Binding describes how the client will communicate with service. We can
understand with an example.

Consider a scenario say, I am creating a service that has to be used by two type of client. One of
the clients will access SOAP using http and other client will access Binary using TCP. How it can
be done? With Web service it is very difficult to achieve, but in WCF its just we need to add
extra endpoint in the configuration file.

   <service name="MathService"
   <endpoint address="http://localhost:8090/MyService/MathService.svc"
<endpoint address="net.tcp://localhost:8080/MyService/MathService.svc"
    <behavior name="MathServiceBehavior">
     <serviceMetadata httpGetEnabled="True"/>
     <serviceDebug includeExceptionDetailInFaults="true" />
See how simple it is in WCF. Microsoft is making everything simple. Cording to its scope:
common behaviors affect all endpoints globally, service behaviors affect only service-related
aspects, endpoint behaviors affect only endpoint-related properties, and operation-level
behaviors affect particular operations.


In the below configuration information, I have mentioned the Behavior at Service level. In the
service behavior I have mention the servieMetadata node with attribute httGetEnabled='true'.
This attribute will specify the publication of the service metadata. Similarly we can add more
behavior to the service.

   <service name="MathService"
    <endpoint address="" contract="IMathService"
    <behavior name="MathServiceBehavior">
     <serviceMetadata httpGetEnabled="True"/>
     <serviceDebug includeExceptionDetailInFaults="true" />


Application can be controlled either through coding, configuring or through combination of
both. Specification mention in the configuration can also be overwritten in code.

Contracts and Service Host

In WCF, all services are exposed as contracts. Contract is a platform-neutral and standard way
of describing what the service does. Mainly there are four types of contracts available in WCF

To top