Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 22nd, 2007, 08:56 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default why serializing class?

Hi,


i read several articles about serialization. I know now that it is a process of converting an object into a stream of data so that it can be is easily transmittable over the network or can be continued in a persistent storage location and that the serializable tag before the class makes the class serializable.

Now i did some tests in order to understand it better, based on a example i found in the Wrox book "beginning asp.net".
I first executed the code below (this (summarized) code produces a virtual simple shopping cart which is put in the Profile of the user) with the attribute "<Serializable()>" and with what follows in web.config:

<profile><properties>
<add name="myCart" serializeAs="Binary" type="wrox.eCommerce.elist"/>
</properties></profile>

After that, i executed it again without the attribute "<Serializable()>" and without "serializeAs="Binary" from web.config.

I couldn't notice any difference (nor in table 'Profiles', nor in the table 'Orders' where the orders are put, nor in the shopping cart, nor in speed , nor in CPU ..).

So my question is:
------------------
what happens (physically on the client/server computer) in this present application when using serialization, what not (physically) happens when not using it?
With other words: what's the practical difference in this application between using <serialisation> _ and not using it? In both cases, data comes into the sql server table and in both cases, data are retrieved when needed.I tested it.
Is the difference the way data is put (and retrieved) into (from) the table (with serialization: binary stream, without:?) Or is the attribute <serialisation> _ just ignored when using Profiles, or ...?

Demonstrate me that using <serialisation> _ is better than not using it.

I thank you in advance
Bob.

The (part of) code:
-------------------

<Serializable()> _
Public Class listitem
        Private _description As String

Public Sub New()
        End Sub

 Public Property description() As String
            Get
                Return _description
            End Get
            Set(ByVal value As String)
                _description = value
            End Set
        End Property
End Class
'--------------------------
 <Serializable()> _
    Public Class elist
....
Public Sub New()
         _items = New List(Of listitem)
End Sub
.....
Public Sub Insert(ByVal Price As Decimal, ByVal description As String)
....
End Class



 
Old March 25th, 2007, 02:45 AM
Authorized User
 
Join Date: Aug 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to bishnupokhrel Send a message via Yahoo to bishnupokhrel
Default

Hi hertendreef,

If i were to make use of this feature (serialisation) then i would do following way ( just an example).

suppose, your web application has lots of configuration on web.config ,and there can be other session values which u need on most of the pages.

now i can make a class ( with serialisation support ) like this

class user
   string stylesheet
   string applicationpath
   string fullname
   string country
   string city
   int id
   string Language
   string dbconnectionstring
   ....
   ....
end class

i can create an object from the class, set all the values, some of those values comes from web.config and some of them come from database after user logs into the application successfully.

now when user navigate from one page to another, i need not retrieve those values from database again and again, i can serialise that object, save this on on session variable and use this again to create new object (deserialize) whenever i need those values. In that case there will be less stress on database , and save lots of coding time.
e.g. u can get those values by simply wrting objUser.stylesheet.

this process may not give full advantage if there is small number of user settings which application has to remember or retreived from database, but if there are large number of values which need to retreived from database, then it can be a big advantage.

this is just an example, there can be other situations, where exact object state need to memorized e.g shopping cart ( if you do not want to save all the visitors cart on database), user profiles on games application etc. in such cases Serializable feature will be very helpful.

hope this helps to you.



Regards
Bishnu Pokharel
[email protected]
http://www.bishnupokharel.com.np/
 
Old March 25th, 2007, 04:29 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi bishnupokhrel,

thanks for replying.

If i understand good, in that shopping cart application, the content of the shopping cart is stored in a variable instead of being written in the table Profiles.

May i assume that if the user quits the application without finalizing his purhases (which make the shopping cart empty), the content is then written in the table, and only at that moment? I ask that because i can't find any code which explicitly does that.
Thanks





 
Old March 25th, 2007, 04:43 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Bishnupokhrel,

two more question:
is the option serializeAs="Binary" in web.config responsible for sending the content in a session variable?

And finally, if i remove '<serialization>' attribute (and also in web.config), does it mean that the content of the shopping cart is directly written in the table 'profiles' instead of in a seeion variable?
Thanks again

 
Old March 25th, 2007, 05:58 AM
Authorized User
 
Join Date: Aug 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to bishnupokhrel Send a message via Yahoo to bishnupokhrel
Default

Hi hertendreef,

pls find my answer after your question.

If i understand good, in that shopping cart application, the content of the shopping cart is stored in a variable instead of being written in the table Profiles.

----> may be ,but i am not sure, i need to have a look on that example. But it is possible to save that too on database if user closes the application ( even though that may not be useful for you)

May i assume that if the user quits the application without finalizing his purhases (which make the shopping cart empty), the content is then written in the table, and only at that moment? I ask that because i can't find any code which explicitly does that.

---> same as above, but that is not automatic, so u must write code if you want data to be saved on database after user quits the application.

is the option serializeAs="Binary" in web.config responsible for sending the content in a session variable?

----->it seems like its saved somewhere permanent which u can retrieve later on next login. Session values get lost once the user left the application. serializeAs=Binary tells system that the myCart object can be serialized ( as binary) ,so that system can serialize the object before storing it.


And finally, if i remove '<serialization>' attribute (and also in web.config), does it mean that the content of the shopping cart is directly written in the table 'profiles' instead of in a seeion variable?

----> if you want to save complex object on profile then you must enable serialization on class ( you can choose if its binary or xml). only simple data type can be stored with out serialization



Regards
Bishnu Pokharel
[email protected]
http://www.bishnupokharel.com.np/
 
Old March 25th, 2007, 11:47 AM
Friend of Wrox
 
Join Date: Apr 2006
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
Serializing object into existing XmlTextWriter planoie .NET Framework 2.0 0 October 15th, 2007 09:54 AM
Error Serializing an object in a web service gabrieldcr2 .NET Web Services 1 December 12th, 2005 04:41 PM
Serializing headers in VB.NET PMNorris XML 0 January 5th, 2004 08:02 AM
Chapter 12 ex1 Serializing objects gillianbc BOOK: Beginning Java 2 1 December 14th, 2003 12:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.