[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# Web Service - SessionIDs, Application bag

Posted on 2004-09-28
4
Medium Priority
?
384 Views
Last Modified: 2008-03-10
Hi,

Im trying to figure out how to use cookies in a Windows Forms application that accesses a web service.
How do I issue a cookie to a client?
How do I store the cookie on the client? Does it need to be explicitly passed to the web service with each method call, by my code?
How do I store a single data value from a client on the server, and later update it for that same client?
Where does it get stored within the application? How do I access data for all the clients in order to, lets say, calculate the average of all data values provided by all the clients that have accessed the service so far?

Thanks for your help! (any code or links much appreciated too)
 

 
0
Comment
Question by:eekj
  • 3
4 Comments
 
LVL 6

Accepted Solution

by:
mogun earned 1500 total points
ID: 12168015
Hi,
You will have to set the EnableSession Property to true in your web method attribute. Then you will have to store the cookie returned by the web method call. Then you can send the same cookie to the web server to maintain session..The following is a link to a sample on MSDN.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebServicesWebMethodAttributeClassEnableSessionTopic.asp

Hope this is useful..

Cheers
Mohan
0
 
LVL 3

Author Comment

by:eekj
ID: 12186252
>Then you will have to store the cookie returned by the web method call
Thanks, this has got me stumped. My compiler wont recognise 'Session[]' or the 'using System.Web.SessionState;'

Suppose Im trying to perform a search through a Web Service...
            private void SubmitBtn_Click(object sender, System.EventArgs e)
            {
                  CookieContainer cookieJar;
                  if (Session["CookieJar"] == null)
                  {
                        cookieJar = new CookieContainer();
                  }
                  else
                  {
                        cookieJar = (CookieContainer) Session["CookieJar"];
                  }
                  proxy.CookieContainer = cookieJar;
                  ResultTB.Text = proxy.Vote(SearchTB.Text);
                  
                  Session["CookieJar"] = cookieJar;
            }

Where does Session[] derive from? What 'using' directive do I need?
0
 
LVL 6

Expert Comment

by:mogun
ID: 12187100
use System.Net namespace..
0
 
LVL 6

Expert Comment

by:mogun
ID: 12187422
I am sorry about the above comment.. It;s a wrong one.. You will have to reference both System.Web and System.Net namespaces in your client application..Then you can use the

System.Web.SessionState.HttpSessionState  

object to create a session object...

Cheers
Mohan
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question