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

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Interview Question >> .NET Framework >> Post New Question Subscribe to Interview Questions

what are contract available in .NET

Posted By :Ashutosh Jha     Posted Date :August 31, 2014    Points :40   Category :.NET Framework 
There are 5 contracts available:
1. Service Contract
2. Operation Contract
3. Data Contract
4. Message Contract
5. Fault Contract

You can also find related Interview Question to what are contract available in .NET  below: 

Which contract is used to documented the view for error occurred in the service to client in wcf?

Fault Contract is used to documented the view for error occurred in the service to client in wcf (More...)

what is service contract in .NET

Service Contract mainly describes the operations which are used in the service or exposed by the service.
Service Operations are also provides the callback functions where the response can also be handled by the client. (More...)

What are the characteristics of WCF Data Contract?

Following are the characteristics of WCF Data Contract:

- A data contract is defined by using a Data Contract Attribute on a class or structure.

- Members of the data structure which will be used by the service need to be marked with the Data Member Attribute.

- Implementation of the same interface by different classes is made possible as only the selected members will be transferred between the service and the client. (More...)

What is data contract equivalence?

Two data contracts are said to be equivalent, if they satisfy the following conditions.
- Both the datacontracts must have same namespace
- Both the datacontracts must have same name
- The data member on data contract must have an equivalent data member on the other.
- The members in the datacontract must appear in the same order in both datacontracts.


The following two data contracts are equal.

public class Person



public string Name;

public string Email_ID;


[DataContract(Name = "Person")]

public class Employee


[DataMember(Name = "Name")]

private string EmpName;

private string address;

[DataMember(Name = "Email_ID")]

private string EmpEmailId;


How do we customize Data Contract Names for Generics types?

We can customize the generic datacontract names by allowing parameters. Find the Example below

[DataContract(Name = "Shape_{1}_brush_and_{0}_shape")]
public class Shape< Square,RedBrush>
// Code not shown.

Here, the Data Contract Name is "Shape_RedBrush_brush_and_Square_shape"
{0} - First Parameter in the generic type.
{1}- Second Parameter in the generic type.

Can we have a message contract as input parameter and data contract as returned parameter in a single operation contract?

No, Input and return parameter should be same as Message contract if we want to use message contract in a operation contract. (More...)

Can you show me an example in how to write a Message Contract in WCF ?


public class EmployeeDetails



public int ID;


public string First_Name;


public string Last_Name;


Message contract can be applied to type using MessageContract attribute as shown above. We can add custom header and custom body by using MessageHeader and MessageBodyMember attribute respectively.


Explain in brief, WCF One Way Contract ?

WCF One Way Contract are methods/operations which are invoked on the service by the client or the server in which either of them do not expect a responce back. For example :-

If a client invokes a method on the service then it will not expect a responce back from the service.

What is the most primary reason to use WCF One Way Contract ?

One way contract is used to ensure that the WCF client does not go in a blocking mode . If your WCF operation contracts are returning nothing and they are doing some heavy process then it is better to use one way contract. (More...)

How is WCF One Way Contract is implemented ?

WCF one way contract is implemented via "IsOneWay = true/false" attribute.
For example :-

interface IMyContract


[OperationContract(IsOneWay = true)]

void MyMethod( );



In WCF, while using one way contract, suppose a client invokes a method and the server while executing it, encounters an error. Will the error message propagate to the client or will the client ever know that there was an error on the server side ?

No, one-way operations cannot return values and any exception thrown on the service side will not make its way to the client. The client will never know whether there was an error or not ! (More...)

What is Sessionful Services in WCF One Way Contract ?

[ServiceContract(SessionMode = SessionMode.Required)]

interface IService


[OperationContract(IsOneWay = true)]

void Method1();


If the client issues a one-way call and then closes the proxy while the method executes, the client will still be blocked until the operation completes.

Please note that the above is a bad design because clients are never meant to be blocked when using one way contract.

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.

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      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend