How to create service using Windows Communication Foundation (WCF)? Part-1

This post basically deals with a detailed explanation of the Windows Communication Foundation and its basic concept. We all know that WCF is very useful functionality for every mobile and web application. Using WCF, a lightweight and secure application can be built by different end-users.

About Windows Communication Foundation (WCF)

Windows Communication Foundation has its code name Indigo. It is a programming platform that allows the creation of new service and runtime systems for building, configuring, and deploying network-distributed services. Actually, WCF is the latest service-oriented technology.

The most fundamental characteristic of WCF is Interoperability. Actually, the windows communication foundation is a unified programming model provided in .Net Framework 3.0.

Basically, WCF service is a combined feature of Web Service, Remoting, MSMQ as well as COM+. The WCF  service provides a common platform for all .NET communication. We can create a WCF application using Microsoft visual studio’s latest version.

The WCF service supports different technologies. Refer to the below figure to know the difference:

The WCF service supports different technologies


Advantages of WCF

WCF is interoperable with other services in comparison to .Net Remoting, whereas the client and service both have to be on .Net.

  • The WCF services provide us better reliability and better security in comparison to ASMX web services.
  • WCF service can be termed as the most secured service. That’s why in WCF, there is no need to make more changes in the source code for implementing the security model as well as changing the binding. We do small changes in our configuration file and it makes our service more secure.
  • WCF has an integrated logging mechanism. Changing the configuration file settings will provide this functionality. Basically, in other technology, the developer has to write the code.

Disadvantages of WCF

In WCF, according to our requirements, it is very difficult to make the right design.

Difference Between WCF and Web Services

The web service is a part of WCF. The WCF service provides much more flexibility and portability for service development in comparison to web services. That’s the reason it is mostly used by users. WCF and web service are quite different. WCF service is the latest service that provides more advantages over Web service.

The table below provides a detailed difference between them:

Features Web Service WCF
Hosting Basically, It can be hosted in IIS Actually, It can also be hosted in IIS, windows activation service, Self-hosting, Windows service
Programming [WebService] attribute set on the top of a class. [ServiceContraact] attribute has set on the top of a class.
Model [WebMethod] attribute refers to the service method that exposed to  the client [OperationContract] attribute refers to the service method that exposed to the client
Operation One-way, Request-Response are the different operations supported in web service One-Way, Request-Response as well as Duplex are different type of operations supported in WCF
XML System.XML.serialization namespace is used for serialization Actually, System.Runtime.Serialization namespace is used for serialization
Encoding XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom XML 1.0, MTOM, Binary, Custom
Transports Can be accessed through HTTP, TCP, Custom Can be accessed through HTTP, TCP, Named pipes, MSMQ, P2P as well as Custom
Protocols Security Security, Reliable messaging as well as Transactions

Different Types of WCF bindings

The windows communication foundation uses built-in bindings to fulfill a user-specific requirement. A custom binding is used in many ways for goal fulfillment.

We have used  System.ServiceModel Namespace for all inbuilt bindings in WCF. Actually, ten built-in bindings are used in WCF:

1. Basic binding

In the basic binding, we are using the BasicHttpBinding class. This service uses ASMX service as a WCF service. Now, our older service which is using ASMX web service can consume new service.

This binding by default used HTTP as well as HTTPS protocol using HTTP protocol for transport and encode the message in UTF 8 text format. Basic binding also allows the use of HTTPS.

2. Web Binding

The web binding is designed for services as an HTTP request by using HTTP-GET as well as HTTP-POST. Inputs including XML or JSON format can be easily derived with the use of this binding along with REST-based services.

This is very much used with social networks for implementing a syndication feed. Consequently, in this binding, we are using the WebHttpBinding class.

3. Web Service (WS) binding

The web service bindings provide us with many WS – * specifications including WS – Reliable Messaging, WS – Transactions, WS – Security, and many more, which are supported by Basic binding. This binding is a combination of basic binding and web service specification.

In web service binding, we use the WSHttpBinding class. This service is the same as Basic binding and uses HTTP as well as HTTPS protocols for transport.

For example:- wsHttpBinding= basicHttpBinding + WS-* specification

4. WS Dual binding

In web service dual binding, we use the WsDualHttpBinding class. Web Service dual binding supports bi-directional communication. It allows clients and services to send and receive messages. This functionality is similar to wsHttpBinding.

5. TCP binding

In TCP binding, we are using the NetTcpBinding class. TCP protocol uses this binding for communication between two machines on the same network. This binding encodes the message in binary format.

The TCP bindings are much faster and more reliable binding as compared to the other, and HTTP protocol, bindings. This service offers a WCF to WCF communication for client and service provider.

6. IPC binding

This binding uses a named pipe for communication between two services on the same machine. The IPC binding is the most secure as well as fast binding as compared to all the bindings. In fact, IPC binding uses the NetNamedPipeBinding class for its processing.

7. MSMQ binding

This binding is using MSMQ for transport and offers support to disconnected messages queued. In these bindings, in fact, we use the NetMsmqBinding class. The MSMQ binding is very useful because it gives us the facility for disconnected scenarios in which the service processes the message at a different time in comparison with the message time send by the client.

8. Federated WS binding

This is a specialized form of web Service binding as well as provides support to federated security. In fact, in these bindings, we use the WSFederationHttpBinding class.

9. Peer Network binding

In peer network binding, we are using a NetPeerTcpBinding class. This binding uses TCP protocol because it uses peer networking as a transport. In this networking, each node acts as a client as well as a server to the other nodes. The tool named torrent uses this binding service because of the file-sharing systems.

10. MSMQ Integration binding

MsmqIntegrationBinding class uses the format of MSMQ integration binding. This binding offers support to communicate with existing systems that communicate via MSMQ.

Concluding Words

I hope this article will help you understand Windows Communication Foundation, its advantages, and bindings types. In my next post, I will describe WCF architecture, the service-oriented architecture concept, and other things.

Leave a Comment