快速上手篇之WCF自定義集合
學(xué)習(xí)WCF時(shí),你可能會(huì)遇到WCF自定義集合問題,這里將介紹WCF自定義集合問題的解決方法,在這里拿出來和大家分享一下。對(duì)于一個(gè)好的分布式系統(tǒng)來講,設(shè)計(jì)時(shí)應(yīng)當(dāng)考慮到異構(gòu)性、開放性、安全性、可擴(kuò)展性、故障處理、并發(fā)性以及透明性等問題?;赟OAP的Web Service可以實(shí)現(xiàn)異構(gòu)環(huán)境的互操作性,保證了跨平臺(tái)的通信。
#T#利用WSE(Web Service Enhancements)可以為ASMX提供安全性的保證。.NET Remoting具有豐富的擴(kuò)展功能,可以創(chuàng)建定制的信道、格式化器和代理程序。Enterprise Service(COM+)提供了對(duì)事務(wù)的支持,其中還包括分布式事務(wù),可實(shí)現(xiàn)故障的恢復(fù)。MSMQ可以支持異步調(diào)用、脫機(jī)連接、斷點(diǎn)連接等功能,利用消息隊(duì)列支持應(yīng)用程序之間的消息傳遞。從功能角度來看,WCF整合了ASMX、.Net Remoting、Enterprise Service、WSE以及MSMQ等現(xiàn)有技術(shù)的優(yōu)點(diǎn),它提供了一種構(gòu)建安全可靠的分布式面向服務(wù)系統(tǒng)的統(tǒng)一的框架模型,使軟件研發(fā)人員在開發(fā)分布式應(yīng)用時(shí)變得更加輕松。
集合元素類的定義如下:
- 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; }
 - }
 - }
 
WCF自定義集合DocumentList則實(shí)現(xiàn)了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
 - }
 















 
 
 






 
 
 
 