問題:
I am very confused about the DataContract
attribute in WCF.我對 WCF 中的DataContract
屬性感到非常困惑。 As per my knowledge it is used for serializating user defined type like classes.據我所知,它用於序列化用戶定義的類型,如類。 I wrote one class which is exposed at client side like this.我寫了一個這樣在客戶端公開的類。
[DataContract]
public class Contact
{
[DataMember]
public int Roll { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Address { get; set; }
[DataMember]
public int Age { get; set; }
}
It is working properly but when I remove DataContract
and DataMember
it also works properly.它工作正常,但是當我刪除DataContract
和DataMember
它也可以正常工作。 I can't understand why it is working properly.我不明白爲什麼它可以正常工作。 Can any one tell me what is the actual use of DataContract
?誰能告訴我DataContract
的實際用途是什麼?
My service contract looks like this我的服務合同看起來像這樣
[ServiceContract]
public interface IRestServiceImpl
{
[OperationContract]
Contact XmlData(string id);
}
解決方案:
參考一: https://en.stackoom.com/question/KIF1參考二: https://stackoom.com/question/KIF1