I found I needed to do a couple of things to preserve Session variables
between Web Service calls:

* The server method needs [WebMethod(EnableSession=true)].  You need to do
this for *every* method where you want to access Session variables.

* The proxy needs a CookieContainer e.g. proxy.CookieContainer = new
System.Net.CookieContainer();  (The browser already handles cookies which is
why it works when you browse to the .asmx.)

Note that all this does is preserve Session state.  It doesn't keep the
object on the server alive between calls: if you want to preserve member
variables you have to manually save them to Session before exiting the
method and restore them in the next one.

Check out the FAQ at Christian Weyer's www.xmlwebservices.cc site -- this
has examples and more information.

Hope this helps,

--
Ivan Towlson
Thales Contact Solutions


-----Original Message-----
From: Marina [mailto:[EMAIL PROTECTED]]
Sent: 11 April 2002 18:31
To: [EMAIL PROTECTED]
Subject: [DOTNET] Web Service Session State


Hi,

I am having trouble getting a Web Service to maintain session state
information. It works if I just browse the asmx file via a browser, but not
otherwise. I found a post in the archives saying to set the
ConnectionGroupName property to a name, and I have done so. However, the
session state does not get maintained and I am still getting two different
session ids.
In fact, the state of the private variables of the web service does not even
get maintained. So if I have an object A, that resides in some DLL (happens
to be a ServicedComponent), and I call WebServiceMethod1, which calls
A.SomeMethod, and this alters some internal variable of A, when I call
WebServiceMethod2, which calls A.SomeOtherMethod, this internal variable
loses the assignment made before.
This was causing a problem, so I decided  to save A as a session variable
hoping to avoid this problem, but during the second call the session
variable I saved A in can't be found because a new session has begun.
Please help!

Thanks,
Marina

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

**********************************************************************

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to