Wednesday, April 7, 2010

differance between data contact and message constarct

Contract Type Member Attributes Description
ServiceContract OperationContract Describes the operations a service can perform. Maps CLR types to WSDL.
DataContract DataMember Describes a data structure. Maps CLR types to XSD.
MessageContract MessageBody, MessageHeader Defines the structure of the message on the wire. Maps CLR types to SOAP messages.


A data contract describes the data that your service operations exchange. Data contracts describe only the data transferred from one side to the other; generally they do not describe the message that carries the data.A message contract would hold all the required information about the message payload itself ie: itself.

Use Message Contracts to implement SOAP Headers, etc.



I would think MessageContract is better suited for this purpose since it is specifically for custom defining

the Message Headers and Message Body.

Basically a WCF Message ( ie message contract NOT data contract ) will call the serializer once for each member in the body and add the result to the output message .

Now if you send a DataContract it will serialize the entire stream.



My requirement is that I need to Pass in Additional Header information to the WCFservice, this I can do with Message Contracts but I need to maintain two set of Contracts one for the Request (which will contain Message Header + body) and another for Reply which will contain Body Only.



Alternatively if use DataContract I don't have option to pass the Headers, but this can be done in other means(by using Server and Client Message Inspectors).

No comments:

Post a Comment