.netWCF

Difference between Data Contract and Message Contract in WCF(Part-10)

 

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://www.techkatak.com/EnterpriseService")]
   public class GetEnterpriseInternetInfoRequest
   {
       [MessageHeader(Namespace = "http://www.techkatak.com/EnterpriseService")]
       public string LicenseKey { get; set; }
   }
     [MessageContract(IsWrapped = true, WrapperName = "GetEnterpriseInternetInfoResponse",
       WrapperNamespace = "http://www.techkatak.com/EnterpriseService")]
   public class GetEnterpriseInternetInfoResponse
   {<br />
   }

© 2015, www.techkatak.com. All rights reserved.

One thought on “Difference between Data Contract and Message Contract in WCF(Part-10)

Comments are closed.