?
Solved

C# Web Service - SessionIDs, Application bag

Posted on 2004-09-28
4
Medium Priority
?
379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 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