One step at a time to learn about the WCF Contract Design of the WCF series-2-SerializableAttribute of the serializable type for complex type serialization

Source: Internet
Author: User

Reading directory

I. Data serialization Flowchart

Ii. SerializableAttribute

I. Data serialization Flowchart

    In WCF, serialization is implemented through the serializer. You can see from this figure that if we want to transmit a data, or if we want to transmit an object, from the client to the server or from the server to the client, we need to serialize the data. to serialize the data, we can use the data contract of DataContractAttribute to implicitly serialize the data, you can also serialize data through specific XMLSerializable serialization methods. You can also add the SerializableAttribute mark to serialize custom objects, no matter which serialization method we use, the data will be converted to an XML file through the serializer, and bound to the XSD file describing the XML, or the XML data will be described through the XSD file, then, the data is sent to the client for object transmission.

  

Ii. SerializableAttribute

.Many CRL types can be serialized

In the general serialization process, if we want to serialize our custom object, add the Serializable mark to the object we need to serialize, we can declare that this object can be serialized by adding this mark. After we add this mark, some standard CRL types of this object can be changed. NET serialization

.All domains are serialized.

In this basic serialization, once we declare this class as a sequence, if these Members in this class are not marked for processing, by default, these members are involved in serialization, and all the domains can be serialized, regardless of the accessibility.

    .Unable to control naming rules and Data Types

After we add this tag or feature, for example, after we perform XML serialization and serialization, the specific Member names in the SOAP data packet are bound with the specific Member names described in our code. Such binding is sometimes not required, however, this serialization method completes this binding for us. This binding improves the coupling between the SOAP message and our code and reduces the flexibility of our code.

1 [Serializable] 2 public class Student 3 {4 // name 5 private string _ Name; 6 public string name 7 {8 get {return _ name ;} 9 set {_ name = value;} 10} 11 // gender 12 private string _ sex; 13 public string Sex14 {15 get {return _ sex ;} 16 set {_ sex = value;} 17} 18 // age 19 private int _ age; 20 public int Age21 {22 get {return _ age ;} 23 set {_ age = value;} 24} 25 // Course set 26 private Course [] _ courses; 27 public Course [] Courses28 {29 get {return _ courses ;} 30 set {_ courses = value;} 31} 32}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.