阅读文档和许多文章后,我认为以下内容应该可以工作,但它不会。已知类型序列化问题
这就是我的数据合同的结构。
[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