Explain About Duplex Contract in WCF? | WCF Interview Question

, ,
In Duplex contract, clients and servers can communicate with each other independently.

Duplex contracts consists of two one-way contracts so that parallel communication is achieved.

Duplex Contracts are needed when the service queries the client for some additional information or the service wants to explicitly raise events on the client.

[ServiceContract(Namespace = "http://www.Microsoft.com",

                     SessionMode = SessionMode.Required, 

                     CallbackContract = typeof(IDuplexCallBack) )]

    

    public interface IService1

    {

        [OperationContract(IsOneWay = true)]

        void getData();        

    }

        

    public interface IDuplexCallBack

    {

        [OperationContract(IsOneWay = true)]

        void filterData(DataSet Output);

    }

In the above code, getData() is a method which will be called by the client on the Service. This getdata() is implemented in the server side.

filterData() is a method which will be called by the server on the Client. This method is implemented in the client side.

CallbackContract is the name of the contract which will be called by the server on the client to raise an event or to get some information from the client.