Dinesh Chand
What is different between Message Contract and Data Contract in WCF?
By Dinesh Chand in XAML on Oct 30 2012
  • Anil Kumar Murmu
    Jan, 2016 12

    Data contracts only provide access to SOAP body(limited to changing the Names and Order of contracts) where as MessageContract provides full access to SOAP XML(both request and response). We can send customized data in SOAP header using using MessageHeader attribute and also customize the SOAP body using MessageBodyMember atttribute. Primary difference is degree of access it provides to customize SOAP request and response.

    • 3
  • Yogesh Jadhav
    Sep, 2013 5

    Data Contracts:
    A data contract is a formal agreement between a service and a client that abstractly describes the data to be exchanged. Data contract can be explicit or implicit. Simple type such as int, string etc has an implicit data contract. User defined object are explicit or Complex type, for which you have to define a Data contract using [DataContract] and [DataMember] attribute. A data contract can be defined as follows:

    • It describes the external format of data passed to and from service operations.
    • It defines the structure and types of data exchanged in service messages.
    • It maps a CLR type to an XML Schema.
    • t defines how data types are serialized and deserialized. Through serialization, you convert an object into a sequence of bytes that can be transmitted over a network. Through deserialization, you reassemble an object from a sequence of bytes that you receive from a calling application.
    • It is a versioning system that allows you to manage changes to structured data.

    Message Contracts:
    Message contracts describe the structure of SOAP messages sent to and from a service and enable you to inspect and control most of the details in the SOAP header and body. Whereas data contracts enable interoperability through the XML Schema Definition (XSD) standard, message contracts enable you to interoperate with any system that communicates through SOAP. Using message contracts gives you complete control over the SOAP message sent to and from a service by providing access to the SOAP headers and bodies directly. This allows use of simple or complex types to define the exact content of the SOAP parts.

    • 2


Most Popular Job Functions


MOST LIKED QUESTIONS