快速上手篇之WCF自定义集合

开发 后端
文章主要介绍了如何定义集合元素类和WCF自定义集合DocumentList则实现了IList接口,希望对大家有帮助。

学习WCF时,你可能会遇到WCF自定义集合问题,这里将介绍WCF自定义集合问题的解决方法,在这里拿出来和大家分享一下。对于一个好的分布式系统来讲,设计时应当考虑到异构性、开放性、安全性、可扩展性、故障处理、并发性以及透明性等问题。基于SOAP的Web Service可以实现异构环境的互操作性,保证了跨平台的通信。

#T#利用WSE(Web Service Enhancements)可以为ASMX提供安全性的保证。.NET Remoting具有丰富的扩展功能,可以创建定制的信道、格式化器和代理程序。Enterprise Service(COM+)提供了对事务的支持,其中还包括分布式事务,可实现故障的恢复。MSMQ可以支持异步调用、脱机连接、断点连接等功能,利用消息队列支持应用程序之间的消息传递。从功能角度来看,WCF整合了ASMX、.Net Remoting、Enterprise Service、WSE以及MSMQ等现有技术的优点,它提供了一种构建安全可靠的分布式面向服务系统的统一的框架模型,使软件研发人员在开发分布式应用时变得更加轻松。

集合元素类的定义如下:

  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.  
  12. [DataMember]  
  13. public string LocalPath  
  14. {  
  15. get { return m_localPath; }  
  16. set { m_localPath = value; }  
  17. }  
  18.  
  19. [DataMember]  
  20. public string FileName  
  21. {  
  22. get { return m_fileName; }  
  23. set { m_fileName = value; }  
  24. }  
  25. [DataMember]  
  26. public FileType FileType  
  27. {  
  28. get { return m_fileType; }  
  29. set { m_fileType = value; }  
  30. }  
  31.  
  32. }  

WCF自定义集合DocumentList则实现了IList接口:

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

2010-03-01 09:56:21

WCF自定义集合类型

2009-07-06 13:49:29

2009-12-22 11:29:27

WCF自定义集合类型

2023-02-04 18:19:39

2009-11-05 09:51:14

WCF基础

2010-02-25 16:27:44

WCF扩展点

2010-03-01 11:10:41

WCF绑定元素

2010-02-25 11:23:29

WCF返回自定义格式

2010-02-24 14:59:52

WCF自定义过滤器

2010-03-02 18:01:07

WCF自定义消息筛选器

2011-08-02 11:17:13

iOS开发 View

2021-10-26 10:07:02

鸿蒙HarmonyOS应用

2022-07-15 16:45:35

slider滑块组件鸿蒙

2022-06-30 14:02:07

鸿蒙开发消息弹窗组件

2015-02-12 15:33:43

微信SDK

2015-02-11 17:49:35

Android源码自定义控件

2023-08-10 17:14:52

鸿蒙自定义弹窗

2022-06-20 15:43:45

switch开关鸿蒙

2009-11-06 16:48:03

WCF简介

2022-02-24 07:56:42

开发Viteesbuild
点赞
收藏

51CTO技术栈公众号