based on my understanding WCF's data contract model was opt-in vs the old opt-out approach of asmx web-services. you have to explicitly include all the fields and types that you require using DataContractAttribute
and DataMemberAttribute
. my experience however has been different.
take a look at the following examples,
///CASE: 1
///Behaves as excpected BoolValue is included but String Value is emitted
[DataContract]
public class CompositeType
{
[DataMember]
public bool BoolValue { get; set; }
public string StringValue { get; set; }
}
///CASE: 2
///All elements are included, as if everything was marked.
public class CompositeType
{
public bool BoolValue { get; set; }
public string StringValue { get; set; }
}
///CASE: 3
/// MyEnum Type is included even though the MyEnum is not marked.
[DataContract]
public class CompositeType
{
[DataMember]
public bool BoolValue { get; set; }
[DataMember]
public string StringValue { get; set; }
[DataMember]
public MyEnum EnumValue{ get; set; }
}
public enum MyEnum
{
hello = 0,
bye = 1
}
///CASE: 4
/// MyEnum Type is no longer included. EnumValue is serialized as a string
[DataContract]
public class CompositeType
{
[DataMember]
public bool BoolValue { get; set; }
[DataMember]
public string StringValue { get; set; }
[DataMember]
public MyEnum EnumValue{ get; set; }
}
[DataContract]
public enum MyEnum
{
hello = 0,
bye = 1
}
///CASE: 5
//Both hello and bye are serilized
public enum MyEnum
{
[EnumMember]
hello = 0,
bye = 1
}
///CASE: 6
//only hello is serilized
[DataContract]
public enum MyEnum
{
[EnumMember]
hello = 0,
bye = 1
}
All I can say is WCF WTF?