快速上手篇之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等现有技术的优点,它提供了一种构建安全可靠的分布式面向服务系统的统一的框架模型,使软件研发人员在开发分布式应用时变得更加轻松。

集合元素类的定义如下:

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

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

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

WCF绑定元素

2010-02-25 16:27:44

WCF扩展点

2010-02-25 11:23:29

WCF返回自定义格式

2010-02-24 14:59:52

WCF自定义过滤器

2009-11-06 16:48:03

WCF简介

2010-03-02 18:01:07

WCF自定义消息筛选器

2025-01-17 07:00:00

2022-02-24 07:56:42

开发Viteesbuild

2022-06-30 14:02:07

鸿蒙开发消息弹窗组件

2011-08-02 11:17:13

iOS开发 View

2022-07-15 16:45:35

slider滑块组件鸿蒙

2021-10-26 10:07:02

鸿蒙HarmonyOS应用

2015-02-11 17:49:35

Android源码自定义控件

2023-08-10 17:14:52

鸿蒙自定义弹窗

2022-06-20 15:43:45

switch开关鸿蒙
点赞
收藏

51CTO技术栈公众号