.NET three sequence modifications

xiaoxiao2021-03-06  97

1. XML Serializer. This is ASP. The way the Web Service SOAP request is sent and accepted by default. Communicate the public properties and members of the object.

2. SOAP Serializer. DOTNET Remoting used object transfer mode. This time the object is required to have a serializable flag.

3. BinarySerializer. Only 2, it is just a binary format.

Code example:

Consider a Person object, there will be some properties such as FullName, unique ID, phone (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 corrections () {// // Todo: Add constructor logic //}

/ / The phone list is assumed to have only three private phone [] _ALLPHONES = new phone [3]; // full name private string fullname = ""; // unique ID = system.guid.newguid () ;

Public String Fullname {get {Return Fullname;} set {fullname = value;}}

///

/// identifier /// public system.guid id {get {return;}}

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 use XML Serializer

I can only see the results. Just sequence fullname

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

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

MontaQuehou

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

Note that GUID and Phone are not serialized. The length is 195 bytes.

All SOAP sequences are serialized all, 2022 bytes.

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

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

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

MontaQuehou

<_a> 120451046

<_b> -8025

<_c> 17783

<_d> 155

<_e> 187

<_f> 62

<_g> 53

<_H> 99

<_i> 190

<_j> 9

<_k> 169

<_phonenumber id = "REF-8"> 13817327101-000

<_phoneType ID = "Ref-9"> Type 1

<_phonenumber id = "REF-10"> 13817327101-001

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

<_phonenumber id = "REF-11"> 13817327101-002

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

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

Binary is also sequence 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-2E-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-6E-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 -02-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-6 1-72-61-74-69-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-00-00-00- 00-00-06-00-00-00-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 --------------------------- See this result You will understand DOTNET Remoting Superiority. HH

转载请注明原文地址:https://www.9cbs.com/read-123686.html

New Post(0)