快速上手篇之WCF自定义集合
创始人
2024-06-11 03:40:24
0

学习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. }  

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...
《非诚勿扰》红人闫凤娇被曝厕所... 【51CTO.com 综合消息360安全专家提醒说,“闫凤娇”、“非诚勿扰”已经被黑客盯上成为了“木...
2012年第四季度互联网状况报... [[71653]]  北京时间4月25日消息,据国外媒体报道,全球知名的云平台公司Akamai Te...