根據我的理解,WCF的數據合同模型與asmx web服務的舊選擇退出方法相比是可選的。您必須明確包含使用DataContractAttribute
和DataMemberAttribute
所需的所有字段和類型。然而我的經歷卻有所不同。不一致的DataContractAttribute行爲
看看下面的實施例,
///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跆拳道?
從我瞭解的看一眼就瞭解,你有當您使用要明確屬性。我會盡力在答案中解釋我想說的。 – shahkalpesh 2009-07-25 04:46:50