閱讀文檔和許多文章後,我認爲以下內容應該可以工作,但它不會。已知類型序列化問題
這就是我的數據合同的結構。
[DataContract]
[KnownType(typeof(Friend))]
public class Person
{
private string name;
[DataMember]
public string Name { get { return name; } set { name = value; }}
private Place location;
[DataMember]
public Place Location { get { return location; } set { location = value; }}
}
[DataContract]
public class Friend : Person
{
private int mobile;
[DataMember]
public int Mobile { get { return mobile; } set { mobile = value; }}
}
[DataContract]
[KnownType(typeof(City))]
public class Place
{
private int altitude;
[DataMember]
public int Altitude { get { return altitude; } set { altitude = value; }}
}
[DataContract]
public class City : Place
{
private int zipCode;
[DataMember]
public int ZipCode { get { return zipCode; } set { zipCode = value; }}
}
客戶端發送下面的示例對象:
Person tom = new Friend();
tom.Name = "Tom";
Place office = new City();
office.Altitude = 500;
office.ZipCode = 900500;
tom.Location = office;
問題對於沒有地方值的一些原因被序列化。
我犯了什麼錯誤?
謝謝。
越來越序列化的高度或任何有關的地方呢? ? – Jeff 2010-09-24 06:14:48
當客戶提交人時沒有將Place的屬性序列化 – mob1lejunkie 2010-09-24 06:23:25
夫妻問題:1)您的客戶端代碼無法編譯:office.ZipCode不是有效的賦值。 2)我把你的數據合約粘貼到VS2010中,做了一個返回「Person」的函數,並使用WCF Test容器調用它。有效。所以問題可能在於問題中沒有顯示的代碼。 – ErnieL 2010-09-26 06:27:45