Click to See Complete Forum and Search --> : this is weird
dky1e
June 6th, 2002, 09:52 AM
I have been playing around with webservices and this is what happens:
I have a functions called void setVal( string val ) and string getVal()
For some reason if I setVal("asdf") getVal() does not return 'asdf'
is it how it supposed to work?
Manish Malik
June 6th, 2002, 07:34 PM
Can you post snippet of your code?
V. Lorenzo
June 7th, 2002, 03:41 AM
Hi:
The reazon is simple, although it is not stright forward.
Each time you invoke a web service a new instance of your web service class is created. When you program web services you are not programming object oriented in the right sense. Web services are just like procedure calls. You are fully responsible of maintaining your class instance (web service class) state.
You need to use Session object as a storage for the session state.
VictorL
dky1e
June 7th, 2002, 08:14 AM
So how can I hold the instance of the webservice class?
From what I understood, everytime I call a function [WebMethod] a new instance of the webservice is created even though I have only one instance of the webservice class in my client application? This does not make sense.
How do I set up a 'session'?
Thanks for clearing it up for me.
V. Lorenzo
June 7th, 2002, 11:19 AM
Hi:
Well, no, you don't have only one instance. You will have one instance for each call...'till the GC deales with it.
¿The solution? It's already in the WebService class, it's Session property. With it you may save the sesion state by saving a state object that should hold all the state you need to preserve.
You also need to enable sesion handling for the class method setting the attribute property EnableSession to true as:
[ WebMethod(EnableSession=true) ]
Take a look at the help : in the help index type WebService class, you will find a topic there by the name 'state management' that could be usefull to you.
VictorL
p.d. I'm currently using the final release 1, maybe this is not in the beta releases' help, but you can find it in the microsoft .Net support site.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.