Data Contract vs Message Contract in WCF – Easy WCF
Skip to content

Data Contract vs Message Contract in WCF

Data Contract in WCF is an agreement between parties (i.e. a service and a client) that describes what type of data will be exchanged between them? On the other hand, Message Contract describes the structure of SOAP message that is passed between parties (i.e. a service and a client).

Using Data Contract, we  control the contents (i.e. Payload data or message body) of a SOAP message while Message Contract provides complete control over structure of SOAP message.

 

Data Contract Message Contract
Data Contract allows us to control the name and order of XML element Message Contract gives the full control on message and Message body. It allows us to change the header and body of XML.
Data Contract is an agreement between Client and Service Message Contract is the structure of XML that is exchanged between Client and Service
Using Data contract, we control payload and message of the body Using Message contract,we control behaviour and structure of the XML message
namespace CustomerService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "ICustomerService" in both code and config file together.
[ServiceContract]
public interface ICustomerService
{
[OperationContract]
Customer GetCustomerDetails(int CustId);
}
[DataContract]
public class Customer
{
private string t_Name;
private int t_Age;
private int t_Salary;
private string t_Designation;
[DataMember]
public string Name
{
get { return t_Name; }
set { t_Name = value; }
}
[MessageContract(IsWrapped = true, WrapperName = "GetEnterpriseInternetInfoRequest",
WrapperNamespace= "http://techkatak.com/EnterpriseService")]
public class GetEnterpriseInternetInfoRequest
{
[MessageHeader(Namespace = "http://techkatak.com/EnterpriseService")]
public string LicenseKey { get; set; }
}
[MessageContract(IsWrapped = true, WrapperName = "GetEnterpriseInternetInfoResponse",
WrapperNamespace = "http://techkatak.com/EnterpriseService")]
public class GetEnterpriseInternetInfoResponse
{<br />
}

© 2015, admin. All rights reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *