一问题描述:
二存在显示不出来的描述:
三WebService后台代码及对象结构:
ProcessResult返回类型的结构:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using System.Xml.Serialization; 7 8 namespace Tang.Golf.DAL.WSData 9 { 10 [Serializable] 11 public class ProcessResult<T> where T : class 12 { 13 private List<T> _list; 14 private string _sessionId; 15 public ProcessResult() 16 { 17 _list = new List<T>(); 18 } 19 [XmlElement(Order = 0)] 20 public virtual int APIStatus { get; set; } 21 [XmlElement(Order = 1)] 22 public string SessionID { 23 get 24 { 25 if (string.IsNullOrEmpty(_sessionId)) 26 { 27 _sessionId = Guid.NewGuid().ToString(); 28 } 29 return _sessionId; 30 } 31 set{ _sessionId = value;} 32 } 33 [XmlIgnore] 34 public T Data { get; set; } 35 /// <summary> 36 /// 集合对象 37 /// </summary> 38 [XmlArray(Order = 2)] 39 public List<T> List 40 { 41 get 42 { 43 if (Data != null) 44 { 45 if (!_list.Contains(Data)) { _list.Add(Data);} 46 } 47 return _list; 48 } 49 set{ _list = value;} 50 } 51 /// <summary> 52 /// 分页列表总数 53 /// </summary> 54 [XmlElement(Order=3)] 55 public int Total { get; set; } 56 [XmlElement(Order = 4)] 57 public int ResultOther { get; set; } 58 /// <summary> 59 /// 返回代码(系统提供代码对照表,这样对多版本的支持比较灵活) 60 /// </summary> 61 [XmlIgnore] 62 public virtual int ReturnCode { get; set; } 63 64 } 65 }
CreditInfo对象结构:
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Runtime.Serialization; 5 using System.Text; 6 using System.Threading.Tasks; 7 using System.Xml.Serialization; 8 9 namespace Tang.Golf.DAL.WSData 10 { 11 /// <summary> 12 /// 积分信息 13 /// </summary> 14 public class CreditInfo 15 { 16 public int CreditId { get; set; } 17 /// <summary> 18 /// 积分余额 19 /// </summary> 20 public decimal CreditBalance { get; set; } 21 /// <summary> 22 /// 兑换值 23 /// </summary> 24 public int ExchangeValue { get; set; } 25 /// <summary> 26 /// 兑换值 27 /// </summary> 28 [XmlIgnore] 29 public string ExchangeValueStr { get; set; } 30 31 /// <summary> 32 /// 积分明细列表 33 /// </summary> 34 public List<CreditDetailInfo> CreditDetailList { get; set; } 35 36 [XmlIgnore] 37 public IQueryable<CreditDetailInfo> Iqueryable_CreditDetailList { get; set; } 38 /// <summary> 39 /// 积分规则列表 40 /// </summary> 41 public List<CreditRuleInfo> CreditRuleList { get; set; } 42 43 44 } 45 }
4.正确的xml输出格式:
1 <?xml version="1.0" encoding="utf-16"?> 2 <ProcessResultOfCreditInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 3 <APIStatus>10</APIStatus> 4 <SessionID>30243396-c828-4efb-9789-67eb2b234d1d</SessionID> 5 <List> 6 <CreditInfo> 7 <CreditId>360</CreditId> 8 <CreditBalance>8000.00</CreditBalance> 9 <ExchangeValue>100</ExchangeValue> 10 <CreditDetailList> 11 <CreditDetailInfo> 12 <CreateDate>2015-05-26</CreateDate> 13 <CreditAmount>100.00</CreditAmount> 14 <Remark>发起约球获得100积分</Remark> 15 </CreditDetailInfo> 16 <CreditDetailInfo> 17 <CreateDate>2015-05-25</CreateDate> 18 <CreditAmount>100.00</CreditAmount> 19 <Remark>发起约球获得100积分</Remark> 20 </CreditDetailInfo> 21 <CreditDetailInfo> 22 <CreateDate>2015-05-25</CreateDate> 23 <CreditAmount>100.00</CreditAmount> 24 <Remark>发起约球获得100积分</Remark> 25 </CreditDetailInfo> 26 <CreditDetailInfo> 27 <CreateDate>2015-05-25</CreateDate> 28 <CreditAmount>100.00</CreditAmount> 29 <Remark>发起约球获得100积分</Remark> 30 </CreditDetailInfo> 31 <CreditDetailInfo> 32 <CreateDate>2015-05-23</CreateDate> 33 <CreditAmount>100.00</CreditAmount> 34 <Remark>发起约球获得100积分</Remark> 35 </CreditDetailInfo> 36 </CreditDetailList> 37 <CreditRuleList> 38 <CreditRuleInfo> 39 <RuleName>参加赛事</RuleName> 40 <RuleCredid>500</RuleCredid> 41 </CreditRuleInfo> 42 <CreditRuleInfo> 43 <RuleName>发起约球</RuleName> 44 <RuleCredid>100</RuleCredid> 45 </CreditRuleInfo> 46 </CreditRuleList> 47 </CreditInfo> 48 </List> 49 <Total>5</Total> 50 <ResultOther>0</ResultOther> 51 </ProcessResultOfCreditInfo>
问题奇怪的地方是单元测试里面CreditRuleList和CreditDetailList始终是可以正确输出集合中对象的属性,但是WebService方法响应却显示不出来,一开始认为是集合为空可能不显示,但是尝试赋值部位空还是不显示。望各位大神不吝赐教。