ubaid.shahid
03-18-2010, 07:22 AM
Hii,
I want to make a Web Service, which can store some values in session. How can I do that???
Here is my sample code.. (which is not working, i.e. always gives result 1, but i want 1,2,3,4 and so on..)
In Web Service
[WebMethod(EnableSession=true)]
public int IncrementSessionCounter()
{
int counter;
if (Context.Session["Counter"] == null)
{
counter = 1;
}
else
{
counter = ((int)Context.Session["Counter"]) + 1;
}
Context.Session["Counter"] = counter;
return counter;
}
In TestPage
System.Net.CookieContainer cookies;
protected void btnButton_Click(object sender, EventArgs e)
{
TestService.TestService ts = new TestService.TestService();
int result;
if (cookies == null)
{
cookies = new CookieContainer();
}
ts.CookieContainer = cookies;
result = ts.IncrementSessionCounter();
taResponse.Value = result.ToString();
}
I want to make a Web Service, which can store some values in session. How can I do that???
Here is my sample code.. (which is not working, i.e. always gives result 1, but i want 1,2,3,4 and so on..)
In Web Service
[WebMethod(EnableSession=true)]
public int IncrementSessionCounter()
{
int counter;
if (Context.Session["Counter"] == null)
{
counter = 1;
}
else
{
counter = ((int)Context.Session["Counter"]) + 1;
}
Context.Session["Counter"] = counter;
return counter;
}
In TestPage
System.Net.CookieContainer cookies;
protected void btnButton_Click(object sender, EventArgs e)
{
TestService.TestService ts = new TestService.TestService();
int result;
if (cookies == null)
{
cookies = new CookieContainer();
}
ts.CookieContainer = cookies;
result = ts.IncrementSessionCounter();
taResponse.Value = result.ToString();
}