473,513 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

object serialization.

AVL
Hi,
I'm new to .net. I need some info on serialization.

What is serialization? Why do we need it? Why objects need to be serialized
if they need to be stored in session or viewstate?

Nov 19 '05 #1
3 2741
From the MSDN: Serialization is the process of converting the state of an
object into a form that can be persisted or transported.

Objects need to be serialized in order to be stored in persistent locations
like session or viewstate. If your object is a string, its serialization is
trivial. If it is a car, serialization is not trivial. What to store depends
on your application requirements. It could be a set of general properties
like make, year, color if you are a dealer, or the detailed list of all
parts if you are on the manufacturer's side, or maintenance history if you
are a garage manager.

Eliyahu

"AVL" <AV*@discussions.microsoft.com> wrote in message
news:57**********************************@microsof t.com...
Hi,
I'm new to .net. I need some info on serialization.

What is serialization? Why do we need it? Why objects need to be serialized if they need to be stored in session or viewstate?

Nov 19 '05 #2
In the basic sense, serialization is the process in which an instance of a
class (an object) is converted into a text string. This is necessary because
sometimes you want to keep rich instances of classes, but you can only store
it in a certain format. Serialization provides a quick way of converting
back and forth.

ViewState stores a collection of objects that maintain their state across
postbacks. The way that ASP.NET accomplishes this is by outputting a hidden
form field named __ViewState to each page it renders (you can see for
yourself). Within the value attribute of that hidden form field contains a
set of objects that make up ViewState.

If you want a rich object to participate in ViewState, you must mark it as
serializable, applying the Serializable attribute to your class.

Hope this helps,
Johann MacDonagh

"AVL" <AV*@discussions.microsoft.com> wrote in message
news:57**********************************@microsof t.com...
Hi,
I'm new to .net. I need some info on serialization.

What is serialization? Why do we need it? Why objects need to be
serialized
if they need to be stored in session or viewstate?

Nov 19 '05 #3
> What is serialization? Why do we need it? Why objects need to be
serialized
if they need to be stored in session or viewstate?

Serialization is the process of converting an object to a data stream. The
process consists of two phases serialization and deserialization. You can
compare these phases to dehydration and rehydration of food.
When an object is serialized, or dehydrated, the state information is
extracted. The common elements (think of water), such as methods are not
included in the data stream. When the object is deserialized, or rehydrated,
a new instance of the object is created and the state is restored form the
serialized data.

You have two important types of serialization; binary and XML. The easiest
to explain is XML serialization. When serializing an object to XML the
member names map directly to the XML element names. Consider the following
object instance.
Person
FirstName (string) "Anders"
LastName (string) "Norås"
Age (int) 28
SayHello (void) (method)

When serialized, the Person instance should result in the following XML
document.
<Person xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://tempuri.org/">
<FirstName>Anders</FirstName>
<LastName>Norås</LastName>
<Age>28</Age>
</Person>

The SayHello method is not part of the object state and hence it is not
included in the XML document.

ViewState stores all objects as text, therefore an object must be serialized
to a text string before it can be stored in ViewState.

Anders Norås
http://dotnetjunkies.com/weblog/anoras
Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
7136
by: NewToDotNet | last post by:
I am getting "Object reference not set to an instance of an object. " when I attempt to open a C# windows service class in design view, although I was able to initially create the service and open...
0
2057
by: Philip Reed | last post by:
I'm trying to write a preferences-handling infrastructure that serializes prefs to XML. Basically I want to read in a common "default" prefs set, then read in the user's prefs and override the...
5
7561
by: Mark Rae | last post by:
Hi, Can anyone please tell me how to convert an object say, a System.Web.Mail.MailMessage object, to a byte array and then convert the byte array to a Base64 string? Any assistance gratefully...
8
12650
by: rawCoder | last post by:
Hi All, I need some advanced samples or references for passing custom objects over the network using sockets. Without using Remoting what are other options in .NET Framework for this binary...
5
2257
by: Matthew | last post by:
I have a nice little Sub that saves data in a class "mySettings" to an XML file. I call it like so: Dim mySettings As mySettings = New mySettings mySettings.value1 = "someText" mySettings.value2...
1
5526
by: J. Askey | last post by:
I am implementing a web service and thought it may be a good idea to return a more complex class (which I have called 'ServiceResponse') in order to wrap the original return value along with two...
3
2142
by: benkial | last post by:
Below is a custom exception class that I created to be shared by my C+ + and C# code. It works fine till I need to pass the exception object through Remoting: every time a FtException is raized in...
0
1893
by: anchiang | last post by:
Hi All, I have XML: <RegistryResponse status="Success" xmlns="urn:oasis:names:tc:ebxml-regrep:registry:xsd:2.1"> <AdhocQueryResponse xmlns="urn:oasis:names:tc:ebxml-regrep:query:xsd:2.1"> ...
3
2112
by: Jeremy | last post by:
I've created a serializable class and put attributes around all the properties that should be serialized. I return the class from a web service, but my problem is that the wsdl for the web service...
0
7267
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7391
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7553
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7120
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7542
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5697
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3247
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
466
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.