Servers and clients are the two most important entities as far as services are concerned. Between the server and the client, the flow of information takes place. There are many ways this communication can be done; some of them are as follows:
- Request-Response
- Simplex
- Duplex
Let's have a look to each of them one by one.
Request-Response
In this process of communication, the client requests data from the server and the server responds with the proper set of data that the client has requested. This type of communication is initiated by the client.
Simplex
This is potentially a one-way communication where either of the two, client or server, on receiving data, needs not respond back to the sender.
Duplex
In this, either the client or the server can initiate the communication. When the latter receives the data, it responds back by sending an acknowledgement to the former.
The Service Part
Here in this article, we will look at how to setup duplex communication in Windows Communication Foundation. To begin with, we create a new WCF Service application project. 
Once the project is ready, remove the IService.cs and Service.svc files from the Solution Explorer. We do this because by default the generated files have a lot of code written in them, which does nothing but confuse. Now add new WCF service .svc file; you can name it anything, I named mine WebDuplex. Once done, we are ready to go.
Open the IWebDuplex interface that is created with our service. Write the exact code in the interface as shown below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace DuplexingSimplified
{
// NOTE: You can use the "Rename" command on the "Refactor"
//menu to change the interface name "IWebDuplex" in
//both code and config file together.
[ServiceContract(CallbackContract = typeof(IWebDuplexCallBack))]
public interface IWebDuplex
{
[OperationContract(IsOneWay = true)]
void DoWork();
}
public interface IWebDuplexCallBack
{
[OperationContract(IsOneWay = true)]
void Broadcast(string msg);
}
}
Let's now talk about what the code above actually means. The interface IWebDuplex is the normal interface like what we create when we write a normal WCF service. It has a function DoWork() that takes nothing and returns nothing, also the mode of communication for the function is one-way, meaning it can only be called by the client and it will return nothing. The functions are defined one way in the case when the client is only required to invoke the function call without waiting for it to return values. That is to say fire-and-forget.
Next we have another interface, IWebDuplexCallBack, defined just below. This interface will be used for the call back. In the first interface IWebDuplex, as you can see, in the servicecontract attribute we have set the callback contract as the interface IWebDuplexCallback. In this interface we have only one function, BroadcastMessage. That also takes one argument and is also one-way. Let's write some more code before explaining the entire concept.
It is now time to have some code written in our svc file. So, open the WebDuplex.svc.cs file, that should have a class named WebDuplex and that class should have the IWebDuplex interface implemented. Here is the entire code of the class.
public class WebDuplex : IWebDuplex
{
public void DoWork()
{
for (int i = 0; i <= 10; i++)
{


Join the conversation! Your thoughts help the community grow.