Asp.net serialization and deserialization of Web Services

Source: Internet
Author: User

 

Serialization: Convert the object to byte [] and then to string. You can convert an object to a convertible format.

Public byte [] serializable_data (Object OBJ)
{
Iformatter formatter = new binaryformatter ();
Memorystream MS = new memorystream ();
Byte [] B;
Formatter. serialize (MS, OBJ );
Ms. Position = 0;
B = new byte [Ms. Length];
Ms. Read (B, 0, B. Length );
Ms. Close ();
Return B;
}

/// <Summary>
/// Convert the byte array into ASCII characters
/// </Summary>
Public String serializable_data (byte [] _ data)
{
Return convert. tobase64string (_ data );
}

 

 

Deserialization: Convert string to byte []-> object.

Public static object deserialize_data (string data)
{
Byte [] bytarray = convert. frombase64string (data );

Iformatter formatter = new binaryformatter ();
Memorystream MS = new memorystream ();
Ms. Write (bytarray, 0, bytarray. Length );
Ms. Position = 0;
Object OBJ = (object) formatter. deserialize (MS );
Return OBJ;
}

Web Service: website service

The Web Service can pass an object, but it must be serialized. Then the client references the server and deserializes the object after instantiation.

Before class serialization, you must add [serializable]

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.