. NET three serialization methods

Source: Internet
Author: User
Tags assert dotnet soap serialization unique id xmlns
1. XML Serializer. This is ASP. NET the way in which the Web Service SOAP requests are sent and accepted by default. Refers to the public properties and members of the serialized object.

2. SOAP Serializer. Dotnet Remoting uses the object transfer method. The objects being transmitted at this time require a Serializable flag.

3. Binaryserializer. Same as 2, it's just binary format.



code example:

Consider a person object with some attributes such as FullName, unique ID, and telephone (up to three. )



[Serializable]
public class Phone
{
private string _phonenumber= "";
private string _phonetype= "";
Public Phone (String phonetype,string phonenumner)
{
_phonenumber=phonenumner;
_phonetype=phonetype;
}

public string PHONEDESCP
{
Get
{
return string. Format ("{0}\t{1}", _phonetype,_phonenumber);



}
}

Public Phone ()
{

}
}




[Serializable]
public class Person
{
Public person ()
{
//
TODO: Add constructor logic here
//
}



Phone List assumes a maximum of three
Private Phone [] _allphones=new phone[3];

Name
private string Fullname= "";

Unique identification
Private System.Guid id=system.guid.newguid ();


public string FullName
{
Get{return FullName;}
Set{fullname=value;}
}

<summary>
Identity
</summary>
Public System.Guid ID
{
Get
{
return ID;
}

}

Public Phone This[int Phoneindex]
{

Get
{
System.Diagnostics.Debug.Assert (phoneindex>=0 && phoneindex<=2);
return _allphones[phoneindex];
}
Set
{
System.Diagnostics.Debug.Assert (phoneindex>=0 && phoneindex<=2);
_allphones[phoneindex]=value;
}
}



}



If you serializer with XML

can only see the results. Only the sequence Hua fullname

---------------------------

---------------------------
<?xml version= "1.0" encoding= "utf-16"?>

<person xmlns:xsd= "Http://www.w3.org/2001/XMLSchema" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" >

<FullName>MontaqueHou</FullName>

</Person>
---------------------------
Ok
---------------------------


Note that both the GUID and Phone are not serialized. Length is 195 bytes.



In the case of SOAP sequences, China serializes all, 2022 bytes.

---------------------------

---------------------------
<soap-env:envelope xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd= "http://www.w3.org/2001/ XmlSchema "xmlns:soap-enc=" http://schemas.xmlsoap.org/soap/encoding/"xmlns:soap-env=" http://schemas.xmlsoap.org /soap/envelope/"xmlns:clr=" http://schemas.microsoft.com/soap/encoding/clr/1.0 "soap-env:encodingstyle=" http:// schemas.xmlsoap.org/soap/encoding/">

<SOAP-ENV:Body>

<a1:person id= "ref-1" xmlns:a1= "http://schemas.microsoft.com/clr/nsassem/Comparation/Comparation%2C%20Version %3d1.0.1698.18683%2c%20culture%3dneutral%2c%20publickeytoken%3dnull ">

<_allphones href= "#ref-3"/>

<fullname id= "Ref-4" >MontaqueHou</fullName>

<id>

<_a>120451046</_a>

<_b>-8025</_b>

<_c>17783</_c>

<_d>155</_d>

<_e>187</_e>

<_f>62</_f>

<_g>53</_g>

<_h>99</_h>

<_i>190</_i>

<_j>9</_j>

<_k>169</_k>

</id>

</a1:Person>

<soap-enc:array id= "ref-3" soap-enc:arraytype= "a1:phone[3" "xmlns:a1=" Http://schemas.microsoft.com/clr/nsassem /comparation/comparation%2c%20version%3d1.0.1698.18683%2c%20culture%3dneutral%2c%20publickeytoken%3dnull ">

<item href= "#ref-5"/>

<item href= "#ref-6"/>

<item href= "#ref-7"/>

</SOAP-ENC:Array>

<a1:phone id= "ref-5" xmlns:a1= "http://schemas.microsoft.com/clr/nsassem/Comparation/Comparation%2C%20Version% 3d1.0.1698.18683%2c%20culture%3dneutral%2c%20publickeytoken%3dnull ">

<_phonenumber id= "Ref-8" >13817327101-000</_phoneNumber>

<_phonetype id= "ref-9" >type 1</_phonetype>

</a1:Phone>

<a1:phone id= "ref-6" xmlns:a1= "http://schemas.microsoft.com/clr/nsassem/Comparation/Comparation%2C%20Version% 3d1.0.1698.18683%2c%20culture%3dneutral%2c%20publickeytoken%3dnull ">

<_phonenumber id= "ref-10" >13817327101-001</_phoneNumber>

<_phonetype href= "#ref-9"/>

</a1:Phone>

<a1:phone id= "ref-7" xmlns:a1= "http://schemas.microsoft.com/clr/nsassem/Comparation/Comparation%2C%20Version% 3d1.0.1698.18683%2c%20culture%3dneutral%2c%20publickeytoken%3dnull ">

<_phonenumber id= "ref-11" >13817327101-002</_phoneNumber>

<_phonetype href= "#ref-9"/>

</a1:Phone>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>


---------------------------
Ok
---------------------------


Binary also sequence Hua all attributes. 517 bytes

---------------------------

---------------------------
00-01-00-00-00- Ff-ff-ff-ff-01-00-00-00-00-00-00-00-0c-02-00-00-00-49-43-6f-6d-70-61-72-61-74-69-6f-6e-2c-20-56-65-72-73-69-6f-6e-3d-31-2 e-30-2e-31-36-39-38-2e-31-38-36-38-33-2c-20-43-75-6c-74-75-72-65-3d-6e-65-75-74-72-61-6c-2c-20-50-75-62-6c-69-63-4b-65-79 -54-6f-6b-65-6e-3d-6e-75-6c-6c-05-01-00-00-00-12-43-6f-6d-70-61-72-61-74-69-6f-6e-2e-50-65-72-73-6f-6e-03-00-00-00-0a-5f- 61-6c-6c-50-68-6f-6e-65-73-08-66-75-6c-6c-4e-61-6d-65-02-69-64-04-01-03-13-43-6f-6d-70-61-72-61-74-69-6f-6e-2e-50-68-6f-6 e-65-5b-5d-02-00-00-00-0b-53-79-73-74-65-6d-2e-47-75-69-64-02-00-00-00-09-03-00-00-00-06-04-00-00-00-0b-4d-6f-6e-74-61-71 -75-65-48-6f-75-04-fb-ff-ff-ff-0b-53-79-73-74-65-6d-2e-47-75-69-64-0b-00-00-00-02-5f-61-02-5f-62-02-5f-63-02-5f-64-02-5f- 65-02-5f-66-02-5f-67-02-5f-68-02-5f-69-02-5f-6a-02-5f-6b-00-00-00-00-00-00-00-00-00-00-00-08-07-07-02-02-02-02-02-02-02-0 2- E6-ef-2d-07-a7-e0-77-45-9b-bb-3e-35-63-be-09-a9-07-03-00-00-00-00-01-00-00-00-03-00-00-00-04-11-43-6f-6d-70-61-72-61-74-6 9-6f-6e-2e-50-68-6f-6e-65-02-00-00-00-09-06-00-00-00-09-07-00-00-00-09-08-00-00-00-05-06-00-00-00-11-43-6f-6d-70-61-72-61-74-69-6f-6e-2e -50-68-6f-6e-65-02-00-00-00-0c-5f-70-68-6f-6e-65-4e-75-6d-62-65-72-0a-5f-70-68-6f-6e-65-54-79-70-65-01-01-02-00-00-00-06- 09-00-00-00-0f-31-33-38-31-37-33-32-37-31-30-31-2d-30-30-30-06-0a-00-00-00-06-54-79-70-65-20-31-01-07-00-00-00-06-00-00-0 0-06-0b-00-00-00-0f-31-33-38-31-37-33-32-37-31-30-31-2d-30-30-31-09-0a-00-00-00-01-08-00-00-00-06-00-00-00-06-0d-00-00-00 -0f-31-33-38-31-37-33-32-37-31-30-31-2d-30-30-32-09-0a-00-00-00-0b
---------------------------
Ok
---------------------------


Seeing this result, you will understand the superiority of dotnet remoting. hh



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.