根据我的理解,WCF 的数据合同模型是选择加入与 asmx Web 服务的旧选择退出方法。您必须明确包括所有需要使用的字段和类型DataContractAttribute
和DataMemberAttribute
。然而,我的经历却有所不同。
看看下面的例子,
///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
}
我只能说WCF WTF?