成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

WCF集合元素基本概念詳解

開發 開發工具
WCF集合元素基本概念對于初學者來說是必須要掌握的,充分掌握這篇文章介紹的內容,可以幫助我們提高對WCF的理解程度。

WCF開發框架中有很多集合元素,在這里我們會為大家詳細介紹這些WCF集合元素的定義方法,和相關使用技巧,希望對大家有所幫助。#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. }  

WCF集合元素自定義集合DocumentList則實現了IList<Document>接口:

 

  1. //which attribute should be applied here?  
  2. public class DocumentList:IList<Document> 
  3. {  
  4. private IList<Document> m_list = null;  
  5. public DocumentList()  
  6. {  
  7. m_list = new List<Document>();  
  8. }  
  9. #region IList<Document> 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<Document> 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<Document> Members  
  65. public IEnumerator<Document> 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  

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

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

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

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

此時,客戶端應用程序可以直接使用數據契約,仍然能夠識別WCF集合元素。

責任編輯:曹凱 來源: 博客園
相關推薦

2010-02-23 16:32:29

WCF服務

2010-02-24 17:17:04

WCF宿主環境

2009-12-21 10:27:52

WCF基本概念

2010-03-01 14:50:30

WCF行為類型

2010-03-01 18:04:35

WCF配置綁定

2010-03-02 13:14:38

WCF MSMQ隊列

2010-03-01 16:25:07

WCF體系架構

2009-12-21 14:37:14

2010-03-01 16:41:04

WCF數據表

2010-03-02 16:22:31

WCF狀態應用

2009-12-21 16:52:02

WCF序列化

2009-12-22 10:16:54

WCF服務狀態

2010-03-02 11:10:43

WCF標準終結點

2010-02-25 14:46:31

2010-07-12 09:43:38

Symbian開發

2009-12-29 18:29:09

Silverlight

2010-03-01 17:57:11

WCF緩存機制

2010-02-02 10:33:22

C++引用

2010-02-02 15:30:05

C++ include

2010-01-25 14:13:36

Android菜單系統
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 毛片.com| 国产主播第一页 | 黄色毛片大全 | 国产美女视频黄a视频免费 国产精品福利视频 | 亚洲成人精品久久 | 在线观看国产视频 | 精品国产乱码久久久久久蜜柚 | 欧美综合在线视频 | 国产在线一区二区 | 国产成人免费网站 | 成人精品久久日伦片大全免费 | www.成人.com | 亚洲国产精品久久久 | 亚洲精品短视频 | av激情在线 | 午夜精品久久久久久不卡欧美一级 | www狠狠爱com | 99久久婷婷国产综合精品首页 | 91精品国产综合久久久亚洲 | 久久噜噜噜精品国产亚洲综合 | 一级毛片免费看 | 伊人网综合在线 | 日韩精品三区 | 亚洲精品视频一区 | 国产成人精品一区二区三区 | 国产三级一区二区三区 | 久久国产高清 | 久草.com| 一级毛片在线播放 | 亚洲一级淫片 | h视频亚洲| 伊人激情综合网 | 91精品国产一区二区三区 | 日本淫视频 | 99re热精品视频 | 欧美日韩大片 | 91精品国模一区二区三区 | 成年人网站免费视频 | 日韩精品一区二区三区视频播放 | 欧美日韩精品久久久免费观看 | 国产在线视频三区 |