[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webservices

Re: Session state and Winforms consuming a web service

Steve Kuhn

7/29/2003 4:58:00 PM

First on all, for your WebMethods that use any Session state variables, you
must use the 'EnableSession=true' WebMethod attribute. This enables session
state variables to be kept in that webmethod. For example:

public class MyService : System.Web.Services.WebService
{
[WebMethod(EnableSession=true)]
public void setMethod(bool value)
{
Session["myBoolVariable"] = value;
}

[WebMethod(EnableSession=true)]
public bool getMethod()
{
return (bool)Session["myBoolVariable"];
}
}

Now, if your using Internet Explorer or any browser that supports cookies,
this is all that you need to do and your Web service should store the
session variables. However, if you use WinForms, you must tell your
application to store the session state variables (which are cookies). You do
this by setting the "CookieContainer" of your Web service variable to a new
CookieContainer. For example, you would put the following code in your
WinForm application:

private void myWinFormMethod()
{
MyService myWebService = new MyService();
myWebService.CookieContainer = new System.Net.CookieContainer();

myWebService.setMethod( true ); // should be saved, if working
bool myBoolVariable = myWebService.getMethod();
}

And that should save your session variable until you get rid of your web
service variable. Hope this helps!

Steve

>>> Henke<henke_nord@hotmail.com> 06/26/03 06:19PM >>>
Hi!

I have a Web service that I access from a Windows form. My problem is that
data doesn't get stored properly in the session state object on the web
service. If I debug the web service I can see that the session state object
gets updated, but the next time my Win app makes a call to the web service
the session state object is null again. What do I have do to with my win
app
to enable session states?

Thanks!
/Henke