serialization, deserialization there is another way to serialize, in addition to binary binary: SOAP Serialization.
Create a class, and also don't forget to serialize the tag [Serializable]
[Serializable] Public classstudentdata{ PublicStudentdata () {}Private string_code; Public stringCode {Get{return_code;} Set{_code =value;} } Private string_name; Public stringName {Get{return_name;} Set{_name =value;} } Private string_nation; Public stringNation {Get{return_nation;} Set{_nation =value;} }}
To add a reference in CS:
Using system.io;//Flow
Using the System.runtime.serialization.formatters.soap;//soap class,
The SOAP class needs to add references to the project first, right--add references to the Reference manager interface, search for SOAP, check and determine:
Code for serializing and deserializing buttons (note the bold part of the text, here is the main difference from binary serialization):
//Serialization Button protected voidButton1_Click (Objectsender, EventArgs e) {Studa SS=NewStuda {Code=TextBox1.Text, Name=TextBox2.Text, Nation=TextBox3.Text}; FileStream FS=NULL; Try { stringPath = Server.MapPath ("Data/bbb.txt");//Map the physical path of the hard disk on the server sideFS =NewFileStream (path, filemode.create);//Create a file stream SoapFormatter bf = new SoapFormatter (); // Soap Formatter Bf. Serialize (FS, SS);//serialization of Objects } finally { if(FS! =NULL) {fs. Close ();//The stream must be closed after it is used. } } } //deserialization protected voidButton2_Click (Objectsender, EventArgs e) { stringPath = Server.MapPath ("Data/bbb.txt"); FileStream FS=NULL; Try{FS=NewFileStream (path, FileMode.Open);//open a file with a streamSoapFormatter by= new SoapFormatter (); // Soap Converters Studa sdata= (Studa) by. Deserialize (FS);//deserialization into an objectLabel1.Text =sdata. Code; Label2.Text=sdata. Name; Label3.text=sdata. Nation; } finally { if(FS! =NULL) {fs. Close (); } } }
Enter text in the text box:
Serialization results:
Here, you can visually see the text information stored in the variable in the object.
Deserialization:
Summary: Binary serialization is not miscible with SOAP serialization, and serialization using a binary method must be deserialized using a binary method. \ \ \ \ In addition, serialization can be put into SQL, and streams using binary serialization can be stored in an IMG-type column of SQL.
20150317--serialization, deserialization (2)