473,387 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Session doesn't work

I developed a Web Service in c# and I tried to use session. I copied
the example from MSDN
[WebMethod(EnableSession = true)]
public int Test()
{
if (Session["HitCounter"] == null)
{
Session["HitCounter"] = 1;
}
else
{
Session["HitCounter"] = ((int)Session["HitCounter"]) + 1;
}
return ((int)Session["HitCounter"]);
}

then I wrote an Symple C# windows application, I linked a Web Reference
and on a button
I put
private void button1_Click(object sender, EventArgs e)
{

ServNav serv = new ServNav(); //
button1.Text = serv.Test().ToString();
}

Now I obtain always 1.
If I change Session with Application, all works fine.

Where is the error? Have you any idea ?

Thanks

Aug 7 '06 #1
2 1856
To use web based session from a windows application you need something that
understands the traffic a session creates. Your consumer has to provide a
CookieContainer object and assign it to the CookieContainer property of the
Web Service proxy as your browser would when it talks to a web server.

http://msdn.microsoft.com/library/de...ainertopic.asp

Regards

John Timney (MVP)
"robig" <ro**********@hotmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
>I developed a Web Service in c# and I tried to use session. I copied
the example from MSDN
[WebMethod(EnableSession = true)]
public int Test()
{
if (Session["HitCounter"] == null)
{
Session["HitCounter"] = 1;
}
else
{
Session["HitCounter"] = ((int)Session["HitCounter"]) + 1;
}
return ((int)Session["HitCounter"]);
}

then I wrote an Symple C# windows application, I linked a Web Reference
and on a button
I put
private void button1_Click(object sender, EventArgs e)
{

ServNav serv = new ServNav(); //
button1.Text = serv.Test().ToString();
}

Now I obtain always 1.
If I change Session with Application, all works fine.

Where is the error? Have you any idea ?

Thanks

Aug 7 '06 #2
Thank you very much. That's the solution !

John Timney (MVP) ha scritto:
To use web based session from a windows application you need something that
understands the traffic a session creates. Your consumer has to provide a
CookieContainer object and assign it to the CookieContainer property of the
Web Service proxy as your browser would when it talks to a web server.

http://msdn.microsoft.com/library/de...ainertopic.asp

Regards

John Timney (MVP)
"robig" <ro**********@hotmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
I developed a Web Service in c# and I tried to use session. I copied
the example from MSDN
[WebMethod(EnableSession = true)]
public int Test()
{
if (Session["HitCounter"] == null)
{
Session["HitCounter"] = 1;
}
else
{
Session["HitCounter"] = ((int)Session["HitCounter"]) + 1;
}
return ((int)Session["HitCounter"]);
}

then I wrote an Symple C# windows application, I linked a Web Reference
and on a button
I put
private void button1_Click(object sender, EventArgs e)
{

ServNav serv = new ServNav(); //
button1.Text = serv.Test().ToString();
}

Now I obtain always 1.
If I change Session with Application, all works fine.

Where is the error? Have you any idea ?

Thanks
Aug 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Peter | last post by:
L.S. I am developing a PHP-login script (on Lycos Tripod) that uses Session to pass on variables. Below is the entire (stripped) structure that I use. It opens a page where you can Set and Read...
1
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains:...
14
by: Paul Yanzick | last post by:
Hello, I am trying to develop a book tracking application for my capstone in school, and am running into a problem. The application is an ASP.Net application written in C#. The first page you...
2
by: Jim Owen | last post by:
I know I';ve posted on this topic before, but it still doesn't work. I have a Session_End event in my Global.asax file, but it never fires. I have gone into my web.config file and in session...
9
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use -...
10
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much...
6
by: Bahman | last post by:
Hello! I have a simple question. Do we have session arrays that we can reference, assign, or select from? Could I please have a sample of how this is done. The obvious syntax that I am...
1
by: zzzbla | last post by:
Hello, I have a project in which I'm trying to embed one site, that uses session stored variables, inside an IFRAME in another site (which for that matter doesn't even use sessions). Problem...
18
by: BillE | last post by:
When a user opens a new IE browser window using File-New-Window the integrity of an application which relies on session state is COMPLETELY undermined. Anyone who overlooks the fact that...
9
by: Josh | last post by:
I run a Joomla website and am familiar with php in some but not all aspects. Currently I am trying to find some solutions related to session handling. Am I correct in saying that "login" is kept...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.