Email: Password:       Forgot Password 
    .netCodeSG
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.
 
TECHNOLOGIES:
 

Contracts In WCF

Article:
Viewed:  738 
Posted On:  11/05/2015 20:11:02 
What is Contracts In WCF? 

 

Contract provides Interoperability to communicate with the client. Contract basically is a type of contract between client and service.

In WCF we have below types of contract.


Service Contract
Operation Contract
Data Contract
Message Contract
Fault Contract

Service Contract:  A service contract defines the operations which are exposed by the service to the outside world. For Exp:


[ServiceContract]
interface IEmployee
{
    [OperationContract]
    EmployeeDetail  GetEmployee(EmployeeInfo emp);
}
 
Operation Contract: We define Operation Contract inside Service Contract. 

[ServiceContract]
interface IEmployee
{
    [OperationContract]
    EmployeeDetail  GetEmployee(EmployeeInfo emp);
}
 
 

Data Contract: Data Contract Describe the Data to be exchanged.

[DataContract]
public class EmployeeInfo
{
 
}

Message Contract: Message contracts give more control over the actual SOAP message for a service operation request or reply. A message contract defines the elements of the message (like as Message Header, Message Body), as well as the message-related settings, such as the level of message security.

 [ServiceContract]

public interface IEmployeeService
{
     [OperationContract]
     EmployeeDetail CalPrice(Employee request);
}
 

[MessageContract]
public class Employee
{
     [MessageHeader]
     public MyHeader SoapHeader { get; set; }
     [MessageBodyMember]
     public EmployeeInfo Employee { get; set; }
}
 
[DataContract]
public class MyHeader
{
     [DataMember]
     public string EmpID { get; set; }
}
 

[DataContract]
public class EmployeeInfo
{
    [DataMember]
     public string EMP_Name { get; set; }

     [DataMember]
     public sring Country { get; set; }

     [DataMember]
     public string City { get; set; }

     [DataMember]
     public string Mobile{ get; set; }
     }
 

Fault Contract: Fault Contract defines the error raised by the service.

[ServiceContract]
interface IEmpContract
{
 [FaultContract(typeof(MyFaultContract1))]
 [FaultContract(typeof(MyFaultContract2))]
 [OperationContract]
 string GetEmployeeAddress();
 

 [OperationContract]
 string ShowEmployee();
 }

  Comment:
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us