2010-10-28 27 views
0

我有Restful wcf服務,返回以下類,但總計和計數字段在到達客戶端時變爲0。但是他們在服務器端有正確的值。公共屬性不在REST wcf服務中反序列化

public class Groups : List<Group> 
{ 
    private int total; 
    private int start; 

    /// <summary> 
    /// Total number of Groups in the result set irrespective of the paging 
    /// </summary> 
    public int Total 
    { 
     get 
     { 
      return total; 
     } 
     set 
     { 
      total = value; 
     } 
    } 

    /// <summary> 
    /// Index (in the full non paged result set) of the first group in the set. 
    /// </summary> 
    public int Start 
    { 
     get 
     { 
      return start; 
     } 
     set 
     { 
      start = value; 
     } 
    } 


} 

問題是,當客戶端從服務調用接收返回值,開始和總場始終爲0,但調試服務代碼,當它返回正確的值,而是由時間談到客戶端他們已經變爲0. 但基類的列表被正確地返回(它不會丟失)

當我返回Group類(這是一個簡單的類(不是從任何派生的))時,它也正常返回。

問題只發生在組集合類的公共字段。

所以我認爲這是一個反序列化問題,並嘗試添加[Datamember]屬性,[可序列化]並實現ISerializable,但沒有任何工作。

任何幫助將不勝感激。

感謝

回答

0

確定這是我做的,如果其他人遇到這個問題。

因爲我發現這是DataContractSerializer的默認行爲,所以向集合添加其他屬性也不是一個好的設計思路。集合應該只是一個項目的集合。 所以我所做的就是如下修改代碼和它的作品

public class Groups 

{ 私人詮釋總; private int start; 私人列表組;

​​

}