新聞中心
WCF作為一個(gè)重要的開(kāi)發(fā)插件,其中有很多比較重要的功能與應(yīng)用技巧,值得我們?nèi)ド钊氲奶接?。那么,我們今天將?huì)為大家詳細(xì)介紹一下有關(guān)WCF自定義集合類(lèi)型的一些應(yīng)用注意事項(xiàng),以幫助大家的實(shí)際開(kāi)發(fā)。#t#

在WCF自定義集合類(lèi)型中,如果作為服務(wù)契約的一部分進(jìn)行發(fā)布,必須要保證以下幾點(diǎn):
1.集合包含的類(lèi)型必須使用[Serializable]和[DataContract]標(biāo)記;
2.集合包含的類(lèi)型屬性必須使用 [DataMember]標(biāo)記,并且,如果是屬性(Property),必須要實(shí)現(xiàn)get和set;
3.集合類(lèi)型必須使用[Serializable]和[CollectionDataContract]標(biāo)記,以及[KnownType]標(biāo)記指向集合包含的子類(lèi)型;
4.集合類(lèi)型必須實(shí)現(xiàn)IEnumerable< T>接口;
5.集合類(lèi)型使用[DataMember]標(biāo)記的IList將集合項(xiàng)向客戶(hù)端公開(kāi).
樣例如下:
- namespace Sharpnessdotnet
- {
- [Serializable]
- [DataContract]
- public class Sharpnessdotnet
- {
- private string name;
- [DataMember]
- public string Name
- {
- get
- {
- return name;
- }
- set
- {
- name = value;
- }
- }
- }
- [Serializable]
- [CollectionDataContract]
- [KnownType(typeof(Sharpnessdotnet))]
- public class SharpnessdotentCollection : IEnumerable
- {
- [DataMember]
- public IList
List; - public SharpnessdotentCollection()
- {
- List = new List
(); - }
- public void Add(Sharpnessdotnet obj)
- {
- List.Add(obj);
- }
- public IEnumerator
GetEnumerator() - {
- return List.GetEnumerator();
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- return List.GetEnumerator();
- }
- }
- }
WCF自定義集合類(lèi)型的基本知識(shí)就為大家介紹到這里。
分享文章:WCF自定義集合類(lèi)型應(yīng)用注意事項(xiàng)探討
本文路徑:http://m.fisionsoft.com.cn/article/cocosge.html


咨詢(xún)
建站咨詢(xún)
