Reputation: 4751
Can someone point (or answer here, if possible) me to the material/reference which describes how to use MessageContrac
t in WCF operations correctly. I have read this document.
I would like to know:
1) What limitations are there while using MessageContract
as return value of the operation contract?
2) What if the class decorated withe the MessageContract
has a property which returns an object of the class which is decorated with XmlRoot
?
3) Are there any limitations or considerations if MessageContract
is going to contain arrays or collections?
Upvotes: 2
Views: 3244
Reputation: 364249
MessageContract
for request description you have to use it for response as well and vice-versa. The only exception are operations returning void or accepting no parameters.DataContractSerializer
by default but you can switch it to XmlSerializer
by marking contract, service or operation with XmlSerailazerFormat
attribute. In such case serialization will ignore DataContract
/ DataMember
attributes and start to use common Xml serialization attributes (including XmlRoot
). What is most important is that MessageContract
is not related to used serializer - it can be used with both DataContract
and Xml serialization.MessageContract
- each is marked with MessageBodyMember
attribute.Upvotes: 3
Reputation: 3413
The MessageContract attribute enables/requires you to specify the format of the entire message for the operation, with finely grained control over how the message is serialized / deserialized, as opposed to the DataContract/DataMember attributes which control whether individual fields are included in the serialization.
The XmlRoot attribute is used by the System.Xml.XmlSerializer class when processing serializable classes; WCF uses the DataContractSerializer which does not use this attribute.
More info in this question: Why does the XmlRoot attribute gets ignored in WCF and how to overcome this
Upvotes: 1