.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Steve Jackman
Imran Ghani
Santhakumar Munuswamy


What are Duplex Contracts in WCF?

WCF Services can communicate with client through a called duplex messaging pattern commonly known as callback. Duplex messaging in WCF can be done over different transports, like TCP, Named Pipes and even HTTP. This is collectively known as Duplex Contracts in WCF.

You can also find related Interview Question to What are Duplex Contracts in WCF?  below: 

What are code contracts?


The System.Diagnostics.Contracts namespace contains static classes that are used to express contracts in your code. (More...)

What is the use of Is Required Property in Data Contracts?

Data Contracts, is used to define Required or NonRequired data members. It can be done with a property named IsRequired on DataMember attribute.

When IsRequired property is true you must populate that datamember before passing it.


public class test



public string NameIsMust;


public string Phone;



What is duplex contract in WCF?

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.

Can you show a sample of Duplex Contract in WCF ?


[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.

State 3 Duplex contract problems in WCF ?

(1) Threading problems can occur if either of the Callback channels are not empty.

(2) If the client and service has a long running work then this pattern doesn't scale very well. It can block the client or the service until the process is completes !

(3) It requires a connection back to the client. And there may be a chance to not connect back due to firewall and Network Address Translation problems.

Note :- It is always better to use Request / Response MEP rather than using Duplex method.

What are Contracts in WCF?

A Contract is basically an agreement between the two parties i.e. Service and Client. In WCF, Contracts can be categorized as behavioral or structural.
1. Behavioral Contracts define that whatoperationsclientcanperform on a service.
o ServiceContract attribute is used to mark a type as Service contract that contains operations.
o OperationContract attributes is used to mark the operations that will be exposed.
o Fault Contract defines what errors are raised by the service being exposed.
2. Structural Contracts
o DataContract attribute define types that will be moved between the parties.
o MessageContract attribute define the structure of SOAP message.

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      



