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.
public interface ICustomerService
Customer GetCustomerDetails(int CustId);
public class Customer
private string t_Name;
private int t_Age;
private int t_Salary;
private string t_Designation;
public string Name
get { return t_Name; }
set { t_Name = value; }
[MessageContract(IsWrapped = true, WrapperName = "GetEnterpriseInternetInfoRequest",
WrapperNamespace= "")]
public class GetEnterpriseInternetInfoRequest
[MessageHeader(Namespace = "")]
public string LicenseKey { get; set; }
[MessageContract(IsWrapped = true, WrapperName = "GetEnterpriseInternetInfoResponse",
WrapperNamespace = "")]
public class GetEnterpriseInternetInfoResponse
{<br />

© 2015, admin. All rights reserved.

Leave a Reply

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