私の理解に基づいて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 WTFのですか?
私は(純粋に読んMSDNドキュメントに基づいて)理解して何から、明示的でなければなりません属性。私は答えで何を言いたいのかを説明しようとします。 – shahkalpesh