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

What is the contract equivalence of WCF set

2025-03-29 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 "what is the equivalence of WCF set contract". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

A set of CollectionDataContractAttribute attributes applied in WCF is called a custom data contract set, otherwise it is a non-custom data contract set. Whether it is a non-custom data contract set or a custom data contract set, as long as their data contract names and loop element names are the same (if the dictionary collection has the same Key and Value), we say they are equivalent.

Because the data contract of the non-custom data contract set and the name of the loop element are determined by the type in the set, the WCF set contract of the non-custom data contract follows the following rules: the WCF set contract of WCF Data Contract is equivalent:

◆ list collections of the same type are considered to have the same data contract (contract) for example: List and int [] are equivalent.

All dictionary collections of ◆ with the same key and value type are also considered to have the same data contract (contract)

The ◆ interface is equivalent to the data contract of the concrete collection class that implements the interface. For example, IList and List are equivalent.

A ◆ non-generic collection is equivalent to a generic WCF collection contract of type Object. For example, List is equivalent to ArrayList, and ArrayList is equivalent to Object [].

This is why, in the above example, the data contract name of the collection type that implements IList and ICollection is ArrayOfint. For example, the following two data contracts are equivalent:

[DataContract (Name= "Customer")] public class Customer1 {[DataMember] public string customerName; [DataMember] public Collection addresses; [DataMember] public string [] telephones;} [DataContract (Name= "Customer")] public class Customer2 {[DataMember] public string customerName; [DataMember] public ICollection addresses; [DataMember] public List telephones;}

Note: Collection and ICollection are equivalent, while string [] and List are also equivalent. So, for the definition of Customer2, we can assign an instance of any collection class that implements the ICollection interface to addresses. Similarly, we can also use the mechanism of defining collection interfaces in the data contract to apply collection types that are not supported by WCF to our WCF application. In other words, we can assign an instance of ReadOnlyCollection to the addresses of Customer2.

This is the end of the content of "what is the equivalence of WCF set contract". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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