Solved

C# Web Service - SessionIDs, Application bag

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

16 Experts available now in Live!

Get 1:1 Help Now