服務代碼:WCF不反序列化值類型。神祕的行爲
[ServiceContract]
public interface IServices
{
[OperationContract]
[XmlSerializerFormat]
GetProductsResponse Getproducts(GetProductsRequest productsrequest);
[OperationContract]
SaveProductsResponse SaveProducts1(SaveProductsRequest1 productsrequest);
}
public class GetProductsRequest
{
[XMLElement]
public string id;
[XMLElement,typeof(Person)]
public Person[] Persons;
}
[DataContract]
public class SaveProductsRequest1
{
[DataMember]
public List<Person> Persons;
}
[DataContract]
public class Person
{
[DataMember]
public int Id;
[DataMember]
public string Name;
[DataMember]
public Sex Sex;
}
[DataContract]
public enum Sex
{
[EnumMember]
Male,
[EnumMember]
Female
}
客戶:
ServicesClient client = new ServicesClient();
SaveProductsRequest1 req = new SaveProductsRequest1();
req.Persons = new List<Person> { new Person { Id = 10, Name = "Al", Sex = Sex.Female} }.ToArray();
client.SaveProducts1(req);
我能夠在服務端來獲取值 '基地'(字符串)。但值10和男(值類型)在服務端重置爲默認值(0和男)。
這隻發生在我爲服務合約中的任何一個方法(本例中爲GetProducts)以及當我將XMLElement放入任何數組屬性和一個附加字符串屬性時在我的GetProducts類中使用XmlSerializerFormat時發生。
是否與WCF運行時問題?
請包括Person類 – Aron 2013-03-06 09:12:34
我們可以看看'Person'是如何聲明的嗎? – 2013-03-06 09:13:17
datacontract是怎麼樣的? – 2013-03-06 09:13:34