June 17, 2010

Getting Started with your first WCF Application

The basics
WCF stands for Windows Communication Foundation with the code name “Indigo”. It is Application User Interface used to create distributed applications using .NET Framework. System.ServiceModel is the name space that is responsible to utilize WCF Concepts.

WCF application is a service, collection of end points in order to communicate with client or service applications. In order to serialize data we make use of System.Runtime.Serialization name space.

WCF Terminology
Addresses The location of service in the form of URI. These are the expose points of services.
Bindings How they communicate with the protocol For ex: The type of network protocol used in WCF.
Contracts the methods exposed by WCF defines the contract.
Service Contract
This attribute that is applied to interfaces in WCF service.
Operation Contract
This is the contract that is applied to methods that are implementing WCF interface.
Channel If client and server wanted to interact with each other . They need to go through the channel that has input message at one end and the other end as results message.
Intermediaries as the name suggests these are programs that act as "middle-man”. They are commonly invisible to the client and services.ex: a firewall ,gateway

Creating WCF Service

Open VS2008 or VS2010 and Create a New Project->WCF->WCF Service Library Project as shown below.

New WCF Project Creation

You have the Service1.svc.cs and IService1.svc.cs in WCF Project
IService.cs is the WCF interface and Service is where exactly you will implement the interface.
You already had methods as GetDataUsingDataContract(), GetData() as methods.

Let us implement one method called GetEmpID()in WCF Service.cs that gets the GUID .
We need to add an operational contract and define a method in IService interface.
Operational contract is mandatory to create WCF service or use WCF method

Create OperationContract in IService1.cs
string GetEmpID(string empId);

Append the below lines of code in the Service1.svc.cs that implements IService interface

public string GetEmpID(string EmpId)
EmpId = Guid.NewGuid().ToString();
return EmpId;

Running WCF Service using Visual Studio 2008

Press f5

Visual Studio itslef creates WCF Test client for theservice where we can test the demo service working or not.
WCF TestClient

Press invoke button

WCF Application Invoke

You can also examine the XML File that contains soap headers in the with xml tabs
And also config file in the config section.
XML and config tabs in WCF Test client


Sathya said...

Hi hima,

this is a great article for learning WCF

Thanks and regards

ןคlคן ๒คкรђเ said...

Good article for newbie.
sharing knowledge always increases knowledge.
thanks for sharing your's

ןคlคן ๒คкรђเ said...

thanks for sharing your knowledge.
great article for a newbie

Pravesh Singh said...


I was reading your article and I would like to appreciate you for making it very simple and understandable. This article gives me a basic idea of First WCF Service and it helped me lot. I have found another posts over the internet which also explained very well. you may check that post...
Creating “Hello World” WCF Application


Implementing a Basic HelloWorld WCF (Windows Communication Foundation) Service

Thank you very much!

There was an error in this gadget