Solved

C# Web Service - SessionIDs, Application bag

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

896 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now