Solved

C# Web Service - SessionIDs, Application bag

Posted on 2004-09-28
4
364 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 500 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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