wcf按正确的顺序序列化和反序列化数据。
顺序是抽象类的第一个属性,然后是子类。
所以原始数据联系人的顺序是Field3->1、Field1->2、Field2->3。
然后将Field1移到抽象类中,顺序为Field1->1、Field3->2、Field2->3。
更改后,客户端和服务器端的属性顺序不匹配。所以你应该改变抽象类的顺序。
[DataContract]
public abstract class Parent
{
// IsRequired is used to test whether has received the property
// if not, it will show error. Order could change the order of the property in message
[DataMember(IsRequired = true,Order =1)]
public int Field3 { get; set; }
[DataMember(IsRequired = true,Order =2)]
public int Field1 { get; set; }
}
我知道这种方法只适用于小的更改,如果您想更改很多,请考虑使用DataContractSurrogate
https://docs.microsoft.com/en-us/dotnet/framework/wcf/extending/data-contract-surrogates