Storing state in the service.vb class?

R

Robin Mark Tucker

Hi, apologies for the cross post, if you also subscribe to the
aspnet.webservices group, I'm new to asp.net so I'm still finding the
newsgroup sweet spots ;)


Anyway, my question is, how can I store state on the server for each
instance of a proxy I use on my
client?


For example if I have, say, as hash table in my services.vb class, with a
web method that creates it:

private m_Hash As Dictionary(Of String, Integer)

<WebMethod()> _
Public Sub CreateHash()

m_Hash.Clear()
m_Hash = new Dictionary(Of String, Integer)

End Sub

<WebMethod()> _
Public Sub AddToHash(ByVal theString as String, ByVal theInteger As
Integer)

m_Hash.Add ( theString, theInteger)

End Sub



and then in my VB.NET (Windows Forms) client application, instantiate the
generated proxy class:



Dim m_Proxy As New MYSERVICE.service

m_Proxy.CreateHash ()
m_Proxy.AddToHash ( "Example", "1" )


Will the hashtable created in the service when "CreateHash" is executed
still be there when "AddToHash" is executed? As m_Proxy is client side, I'm
wondering if an instance of the service class on the server exists for as
long as it does. What is the "best" practice way to store state like this?

Thanks



Robin Tucker
 
B

bruce barker \(sqlwork.com\)

http applications (and webservices) are stateless. this means the life of a
web service class instance (server side) is one request (method call).

so in your example:

for
m_Proxy.CreateHash ()
the server will create new instantance of the serivice class and call
CreateHash
the server will send a response, then release the instance

for
m_Proxy.AddToHash ( "Example", "1" )
the server will create new instantance of the serivice class and call
AddToHash
the server will error becuase hastable is not defined
the server will send an error response, then release the instance

so you first job is to decide where on the server you will store state. also
when to release it as a client may call CreateHash, but never call again.

you second job is to determine how to identify the sam client is calling
back. .net session manager uses a cookie, but then you client would have to
support cookies with web service calls. the most common approach is to
return a ticket, that is passed on subsiquent request, and to store the
state in a database.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top