日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
WCF集合元素基本概念詳解

WCF開發(fā)框架中有很多集合元素,在這里我們會為大家詳細介紹這些WCF集合元素的定義方法,和相關(guān)使用技巧,希望對大家有所幫助。#t#

WCF集合元素類的定義如下:

  1. public enum FileType
  2. {
  3. TXT,DOC,HTML,OTHER
  4. }
  5. [DataContract]
  6. public class Document
  7. {
  8. private string m_localPath;
  9. private string m_fileName;
  10. private FileType m_fileType; 
  11. [DataMember]
  12. public string LocalPath
  13. {
  14. get { return m_localPath; }
  15. set { m_localPath = value; }
  16. }
  17. [DataMember]
  18. public string FileName
  19. {
  20. get { return m_fileName; }
  21. set { m_fileName = value; }
  22. }
  23. [DataMember]
  24. public FileType FileType
  25. {
  26. get { return m_fileType; }
  27. set { m_fileType = value; }
  28. }
  29. }

WCF集合元素自定義集合DocumentList則實現(xiàn)了IList接口:

 
 
 
  1. //which attribute should be applied here?
  2. public class DocumentList:IList
  3. {
  4. private IList m_list = null;
  5. public DocumentList()
  6. {
  7. m_list = new List();
  8. }
  9. #region IList Members
  10. public int IndexOf(Document item)
  11. {
  12. return m_list.IndexOf(item);
  13. }
  14. public void Insert(int index, Document item)
  15. {
  16. m_list.Insert(index,item);
  17. }
  18. public void RemoveAt(int index)
  19. {
  20. m_list.RemoveAt(index);
  21. }
  22. public Document this[int index]
  23. {
  24. get
  25. {
  26. return m_list[index];
  27. }
  28. set
  29. {
  30. m_list[index] = value;
  31. }
  32. }
  33. #endregion
  34. #region ICollection Members
  35. public void Add(Document item)
  36. {
  37. m_list.Add(item);
  38. }
  39. public void Clear()
  40. {
  41. m_list.Clear();
  42. }
  43. public bool Contains(Document item)
  44. {
  45. return m_list.Contains(item);
  46. }
  47. public void CopyTo(Document[] array, int arrayIndex)
  48. {
  49. m_list.CopyTo(array,arrayIndex);
  50. }
  51. public int Count
  52. {
  53. get { return m_list.Count; }
  54. }
  55. public bool IsReadOnly
  56. {
  57. get { return m_list.IsReadOnly; }
  58. }
  59. public bool Remove(Document item)
  60. {
  61. return m_list.Remove(item);
  62. }
  63. #endregion
  64. #region IEnumerable Members
  65. public IEnumerator GetEnumerator()
  66. {
  67. return m_list.GetEnumerator();
  68. }
  69. #endregion
  70. #region IEnumerable Members
  71. IEnumerator IEnumerable.GetEnumerator()
  72. {
  73. return ((IEnumerable)m_list).GetEnumerator();
  74. }
  75. #endregion
  76. }

注意,對于自定義集合DocumentList而言,我們不能應(yīng)用[DataContract]特性,否則會在服務(wù)操作中無法返回正確的DocumentList對象。例如如下的服務(wù)操作定義,實際上無法獲得正確的DocumentList值:

 
 
 
  1. [OperationContract]
  2. [FaultContract(typeof
    (DirectoryNotFoundException))]
  3. DocumentList FetchDocuments
    (string homeDir);

我們應(yīng)該為DocumentList施加[CollectionDataContract]或者[Serializable],建議采用前者。因為對于自定義集合而言,如果是泛型集合,還可以利用Name屬性制定導(dǎo)出元數(shù)據(jù)生成的類型名。不過,對于本例的集合而言,由于沒有泛型參數(shù),則無所謂了。為了在導(dǎo)出元數(shù)據(jù)時識別集合的元素Document類型,當(dāng)然,還需要施加KnowTypeAttribute,最后的定義修改如下:

 
 
 
  1. [KnownType(typeof(Document))]
  2. [CollectionDataContract] 
  3. [Serializable]
  4. public class DocumentList:
    IList
  5. {}

此時,客戶端應(yīng)用程序可以直接使用數(shù)據(jù)契約,仍然能夠識別WCF集合元素。


本文標(biāo)題:WCF集合元素基本概念詳解
網(wǎng)站地址:http://m.5511xx.com/article/copdddj.html