An Overview of Windows Communication Foundation

An Overview of Windows Communication Foundation

What is WCF?

WCF stands for Windows Communication Foundation and its code name is “indigo”. WCF is released as part of .NET Framework 3.0 and it is a framework for building, deploying interoperable distributed services and configuring. It also provides built-in support for logging. You can also enable and disable logging using configuration. WCF services are not tightly bound to a protocol. At the time of designing of WCF services, we do not have to worry about any protocol. It supports many transport schemes

  • HTTP/HTTPS
  • IPC
  • TCP
  • Peer Network
  • Service Bus
  • MSMQ

It is the progressive version of Web Service. WCF Services endpoints must have three things i.e. Address tells us where the WCF service is hosted, Binding decides the protocol of the service and Contract defines what services operations are available to the client to use.


<endpointaddress="EmployeeService"binding="basicHttpBinding"contract="StudentService.IStudentService">
</endpoint>


WCF Supports several types of Contract such as

 

[ServiceContract]

          It uses which service is exposed to the client. We use it with the interfaces or class

[OperationContract]

          It is used which operation can perform by the client, it uses for class methods.

[DataContract]

          It used to explain which data types are going to get and set the service.

[MessageContract]

          It interacts directly through messages.

[FaultContract]

          It handles with errors

Example code of the uses of Contracts in WCF


[ServiceContract]

    publicinterfaceIStudentService

    {

        [OperationContract]

        Student GetStudent(int Id);

 

        [OperationContract]

        void SetStudent(Student student);

 

    }


WCF hosting needs to be hosted on a windows process named host process. Single host can host multiple services and it can be hosted in many ways such as

  • IIS
  • WAS Hosting
  • Custom Hosting in IIS
  • Windows Server AppFabric
  • Self-Hosting

Example of Self Hosting


using (ServiceHost host = newServiceHost(typeof(StudentService.StudentService)))

            {

                host.Open();

                Console.WriteLine("Host started At " + DateTime.Now.ToString());

                Console.ReadLine();

            }


Comments