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}