自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

關(guān)于WCF集合類型中數(shù)據(jù)契約詳細(xì)介紹

開發(fā) 后端
WCF集合類型數(shù)據(jù)契約(協(xié)定)的格式是(不包括“+”):列表集合、循環(huán)元素名稱、字典集合、循環(huán)元素名稱,文章有詳細(xì)的介紹。

經(jīng)過長(zhǎng)時(shí)間學(xué)習(xí)WCF,于是和大家分享一下關(guān)于集合的數(shù)據(jù)契約(協(xié)定)缺省名稱,看完本文你肯定有不少收獲,希望本文能教會(huì)你更多東西。

#T#缺省情況下,WCF框架對(duì)集合類型是內(nèi)建支持的,也就說你不需要應(yīng)用任何屬性,就可以將集合應(yīng)用在數(shù)據(jù)契約(協(xié)定)中,但前提是集合中的元素必須是應(yīng)用了屬性或者是可序列化的類型。這時(shí),數(shù)據(jù)契約(協(xié)定)名稱和命名空間就依賴WCF集合類型中包含的元素的類型的名稱和命名空間了,它們不受WCF集合類型本身的名稱和命名空間的影響。

WCF缺省集合類型數(shù)據(jù)契約(協(xié)定)的格式是(不包括“+”):
◆列表集合:名稱:ArrayOf+集合中包含的元素類型
◆循環(huán)元素名稱:集合中包含的元素類型
◆字典集合:名稱:ArrayOfKeyValueOf+集合中Key的類型+集合中包含的對(duì)象類型
◆循環(huán)元素名稱:KeyValueOf+集合中Key的類型+集合中包含的對(duì)象類型

例如:

  1. MyCollection1:IList<int>{…}的數(shù)據(jù)契約名稱就是:ArrayOfint  
  2. MyCollection2:ICollection<int>{…}的數(shù)據(jù)契約名稱就是:ArrayOfint  
  3. MyDictionary1:Dictionary<int,int>{…}的數(shù)據(jù)契約名稱就是:ArrayOfKeyValueOfintint  
  4. MyCollection3:ArrayList{…}的數(shù)據(jù)契約名稱就是:ArrayOfanyType  
  5. MyDictionary2:Dictionary<int,object>{…}的數(shù)據(jù)契約名稱就是:ArrayOfKeyValueOfintanyType 

注意:如果是object的話,使用的是anyType,因?yàn)樵赟chema中所有類型的基類是anyType.

如果WCF集合類型是應(yīng)用于某個(gè)數(shù)據(jù)契約類型中時(shí),那么它的名稱將是字段名稱,如下面Customer的定義以及序列化后的表示:

  1. [DataContract]  
  2. publicclassCustomer  
  3. {  
  4. [DataMember]  
  5. publicList<string>addresses=newList<string>{"Beijing","ShangHai"};  
  6. [DataMember]  
  7. publicDictionary<int,object>telephones=newDictionary<int,object>{  
  8. {1,"010-82371234"},  
  9. {2,"021-56781234"}};  
  10. }  
  11. <Customerxmlns:iCustomerxmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
  12. xmlns="http://schemas.datacontract.org/2004/07/WCFTestSerializer"> 
  13. <addressesxmlns:d2p1addressesxmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> 
  14. <d2p1:string>Beijing</d2p1:string> 
  15. <d2p1:string>ShangHai</d2p1:string> 
  16. </addresses> 
  17. <telephones 
  18. xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> 
  19. <d2p1:KeyValueOfintanyType> 
  20. <d2p1:Key>1</d2p1:Key> 
  21. <d2p1:Valuexmlns:d4p1d2p1:Valuexmlns:d4p1="http://www.w3.org/2001/XMLSchema"i:type="d4p1:string">010-82371234</d2p1:Value> 
  22. </d2p1:KeyValueOfintanyType> 
  23. <d2p1:KeyValueOfintanyType> 
  24. <d2p1:Key>2</d2p1:Key> 
  25. <d2p1:Valuexmlns:d4p1d2p1:Valuexmlns:d4p1="http://www.w3.org/2001/XMLSchema"i:type="d4p1:string">021-56781234</d2p1:Value> 
  26. </d2p1:KeyValueOfintanyType> 
  27. </telephones> 
  28. </Customer> 
責(zé)任編輯:田樹 來源: 博客
相關(guān)推薦

2009-11-05 16:27:51

WCF數(shù)據(jù)契約

2010-02-23 13:46:37

WCF數(shù)據(jù)契約

2010-02-23 13:54:43

WCF非定制數(shù)據(jù)契約集

2010-02-23 17:44:22

WCF數(shù)據(jù)契約

2009-11-09 13:47:22

WCF Stream操

2009-11-09 17:30:20

WCF元數(shù)據(jù)

2010-02-24 17:36:33

WCF集合數(shù)據(jù)契約

2009-12-22 11:29:27

WCF自定義集合類型

2009-11-09 09:23:10

WCF數(shù)據(jù)契約

2010-02-22 15:27:05

WCF數(shù)據(jù)契約

2010-02-24 17:47:05

WCF集合類型

2009-11-09 14:46:09

WCF集合契約等價(jià)

2009-12-08 09:21:13

WCF數(shù)據(jù)量

2009-12-22 15:02:40

WCF限流

2009-11-09 09:34:07

WCF集合

2009-12-07 18:33:31

WCF Service

2009-11-09 17:55:13

WCF緩存

2009-12-08 16:09:02

WCF消息

2011-07-11 11:02:12

JAVA集合框架

2010-02-22 13:56:35

WCF服務(wù)契約
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)