session state ???

C

cmrchs

Hi,

I have following function in a WebService-class :

[WebMethod(EnableSession=true)]
public int Count()
{
if ( null == Session["mycounter"] )
Session["mycounter"] = 0;
else
m_counter = (int)Session["mycounter"];
Session["mycounter"] = ++m_counter;
return m_counter;
}
'm_counter' is a datamember of the class.

When calling the WS-function from IExplorer several times do I get an incremented count as return value : OK

.... but invoking the same WS-function from a ConsoleApp always returns me the same value of 1 ???

result = calc.Count();
result = calc.Count();
Console.WriteLine("Count : {0}", result);

how come ?
thnx
Chris

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
M

Mickey Williams [C# MVP]

Are you managing the cookie in your console app? You must send the cookie
up - otherwise, ASP.NET will have no way to provide session management.
State management is usually not a good idea for web services, as most
clients have no idea that they need to push a cookie.


--
Mickey Williams
Author, "Visual C# .NET Core Ref", MS Press
www.neudesic.com
www.servergeek.com


Chris C said:
Hi,

I have following function in a WebService-class :

[WebMethod(EnableSession=true)]
public int Count()
{
if ( null == Session["mycounter"] )
Session["mycounter"] = 0;
else
m_counter = (int)Session["mycounter"];
Session["mycounter"] = ++m_counter;
return m_counter;
}
'm_counter' is a datamember of the class.

When calling the WS-function from IExplorer several times do I get an
incremented count as return value : OK
... but invoking the same WS-function from a ConsoleApp always returns me the same value of 1 ???

result = calc.Count();
result = calc.Count();
Console.WriteLine("Count : {0}", result);

how come ?
thnx
Chris

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
 
N

Nick Losev

Hi Chris,

Try to instantiate CookieContainer class for CookieContainer property of
your using proxy object.

Chris C said:
Hi,

I have following function in a WebService-class :

[WebMethod(EnableSession=true)]
public int Count()
{
if ( null == Session["mycounter"] )
Session["mycounter"] = 0;
else
m_counter = (int)Session["mycounter"];
Session["mycounter"] = ++m_counter;
return m_counter;
}
'm_counter' is a datamember of the class.

When calling the WS-function from IExplorer several times do I get an
incremented count as return value : OK
... but invoking the same WS-function from a ConsoleApp always returns me the same value of 1 ???

result = calc.Count();
result = calc.Count();
Console.WriteLine("Count : {0}", result);

how come ?
thnx
Chris

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
 

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

Similar Threads

Object.Equals() and GethashCode() 3
string is sealed 3
Session object gone! 3
using delegate via a thread ??? 2
ASP to ASP.NET Session 4
using Session-object ?? 1
DataRow problem 3
Get the last record in a dataset 3

Top