Wednesday, April 7, 2010


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.

Q:I'm not sure when I should use a message contract. In fact why would I use a message? After all my operation parameters get serialized into a soap envelope automatically.

So when would I use a message and when would I use a serilizable class?
2. 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.

3. Not wanting to use DataContract versioning and to keep a open Message type across service operations.

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