Windows Communication Foundation in .NET

Windows Communication Foundation (WCF) is a technology for developing applications based on service-oriented architecture (SOA). WCF offers unified model for developing services accessible to all user in their native communication options. it combines almost all .net and other technology supports.
 
Before creating the WCF service we must know the basic WCF concepts and these concepts are WCF ABCs.
 
There are many terms and concepts around WCF, such as address, binding, contract, endpoint, behavior, hosting, and channels. Understanding these terms is very helpful when using WCF.
 
Address  

 The WCF Address is a specific location for a service. here we mention our service address using which clients can communicate with our service.
 
Binding

In this section we specify the type of communication that is required between client and service for providing functionality and access. This is where WCF different compared to web service and other services. web service provides only single binding option and that is HTTP.wcf service provides multiple binding option for a single .net component or service.
 
Contracts 

A WCF contract is a set of specifications that define the interfaces of a WCF service. A WCF service communicates with other applications according to its contracts. There are several types of WCF contracts, such as Service Contract, Operation Contract, Data Contract, Message Contract, and Fault Contract.
 
Service Contract

Service contract is wcf attribute which specifies the type to be consumed as part of service communication. we can use this attribute for almost all user defined types.

// Employee ServiceContract

    [ServiceContract]

    public interface IEmployeeService

    {

        // Define the OperationContact here….

    }

 
Operation Contract 

This attribute make our method accessible from the service contract type. Operation contract should be specify for method which we want to exposed too user.
A service contract should have at least one operation contract.

// Employee ServiceContract

    [ServiceContract]

    public interface IEmployeeService

    {

        // Define the GetEmployeeFullName OperationContract here….

        [OperationContract]

        String GetEmployeeFullName(int employeetId);

 

        // Define the GetEmployeeInfo OperationContract here….

        [OperationContract]

        EmployeeInformation GetEmployeeInfo(int employeeId);

    }

 
 
Data Contract

In our Service if any complex type is used we must specify that type with [Datacontract] attribute. so that WCF expose them as xsd's  and other forms - so that user can understand and prepare for that complex type.

[DataContract]

public class EmployeeInformation

{

    // Define the Datamembers here….

}

 

DataMember 

Inside [DataContract] only [DataMember]  members are visible to client. Which means we can project accessible members as service accessible.

[DataContract]

public class EmployeeInformation

{

      _employeeId = empId;

 

    [DataMember]

    public int EmployeeId

    {

        get { return _employeeId ; }

        set { _employeeId = value; }

    } 

}

  
This is just an introduction to the Windows Communication Foundation framework. I will include details about creating wcf service and consuming the service in my next article.