Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / August 2005

Tip: Looking for answers? Try searching our database.

Session state handling

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Riga - 31 Aug 2005 02:22 GMT
Hi guys,
I'm making a webservice that will be used by a pocketpc app. I want to be
able to keep an instance of some things (there are 2 collections and possibly
a database connection).

Is there a way to keep the state of the server? So that these collections
are not lost between method calls?
Rami Farhat - 31 Aug 2005 15:12 GMT
Hi,

Since webservices are essentially statless you would need to pass a token
indentifying the user with every method call and using the Session object on
the webservice side. In normal windows applications this can be done by
setting CookieContainer property on the webservice proxy.

This unfortunatly is  not supported in the .net compact framework as far as
I know so you cant use the session and you have to do things manually to
maintain state as follows:

1- Provide a method to  generate a token id for the user.
2-Pass the id with every method call to the web service.
3-On the webservice side you can store the client data  by using
the asp .net cache - System.Web.HttpContext.Current.Cache (warning this
cache isn't replicated so it won't work if you have a webfarm)

//just a quick code snippet webservice side//
//i'm storing a user string you could store any other object//

[WebMethod]
        public string GetMyToken()
        {
            //just returning a unique id to identify the user usually this would be
done after authentication//
            return System.Guid.NewGuid().ToString();
        }

        [WebMethod]
        public void SaveMyStuff(string stuff,string token)
        {
               
            //save  the user string in the asp.net cache//
             System.Web.HttpContext.Current.Cache[token]=stuff;
        }

        [WebMethod]
        public string GetMyStuff(string token)
        {
            //get the user string identified by the token//
            return (string) System.Web.HttpContext.Current.Cache[token];
        } code snippet webservice side//

Regards,

Rami Farhat

> Hi guys,
> I'm making a webservice that will be used by a pocketpc app. I want to be
[quoted text clipped - 3 lines]
> Is there a way to keep the state of the server? So that these collections
> are not lost between method calls?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.