Session doesn't work

R

robig

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
 
R

robig

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/d...ebclientprotocolclasscookiecontainertopic.asp

Regards

John Timney (MVP)


robig said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top