Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Case Analysis of data contract in WCF Collection Type

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "Data Contract Instance Analysis in WCF Collection Type". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to handle these situations! I hope you can read carefully and learn something!

By default, the WCF framework has built-in support for collection types, meaning that you don't need to apply any attributes to apply collections to a data contract (contract), provided that the elements in the collection have attributes applied or serializable types. In this case, the data contract name and namespace depend on the names and namespaces of the types of elements contained in the WCF collection type, and they are not affected by the names and namespaces of the WCF collection type itself.

The format of the WCF default collection type data contract (contract) is (excluding "+"):

◆ List collection: Name: ArrayOf+ Element types contained in the collection

Loop element name: the type of element contained in the collection

◆ Dictionary collection: Name: ArrayOfKeyValueOf+ type of Key in collection + type of object contained in collection

◆ Loop element name: KeyValueOf+ type of Key in collection + type of object contained in collection

For example:

MyCollection1:IList{…} has the following data contract name: ArrayOfint MyCollection2:ICollection{…} data contract name is: ArrayOfint MyDictionary1:Dictionary{…} data contract name is: ArrayOfKeyValueOfintMyCollection 3:ArrayList{…} data contract name is: ArrayOfanyType MyDictionary2:Dictionary{…} data contract name is: ArrayOfKeyValueOfintanyType

Note: If it is an object, it is anyType, because the base class of all types in Schema is anyType.

If the WCF collection type is applied to a data contract type, then its name will be the field name, such as the following definition of Customer and its serialized representation:

[DataContract] publicclassCustomer { [DataMember] publicListaddresses=newList{"Beijing","ShangHai"}; [DataMember] publicDictionarytelephones=newDictionary{ {1,"010-82371234"}, {2,"021-56781234"}}; } Beijing ShangHai 1 010-82371234 2 021-56781234 "WCF collection type data contract instance analysis" content introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report