Reputation: 1
I have a problem in session concept of asp.net web services, how to implement in a application?
and also i have a problem in eval in asp.net actually what is the use of eval
<asp:ImageButton ID="imgbtnDelete" ImageUrl="~/cpanel/images/icons/table/actions-delete.png"
runat="server" CommandArgument='<%#Eval("JobID")%>' OnClick="imgbtnDelete_Click">
Upvotes: 0
Views: 253
Reputation: 223
public class MyDemo : System.Web.Services.WebService
{
[WebMethod (EnableSession = true)]
public string HelloWorld()
{
// get the Count out of Session State
int? Count = (int?)Session["Count"];
if (Count == null)
Count = 0;
// increment and store the count
Count++;
Session["Count"] = Count;
return "Hello World - Call Number: " + Count.ToString();
}
}
[WebMethod (EnableSession = true)]-This attribute enables session in web service
From client application- on button click event we have to write this to access web service
localhost.MyDemo MyService;
// try to get the proxy from Session state
MyService = Session["MyService"] as localhost.MyDemo;
if (MyService == null)
{
// create the proxy
MyService = new localhost.MyDemo();
// create a container for the SessionID cookie
MyService.CookieContainer = new CookieContainer();
// store it in Session for next usage
Session["MyService"] = MyService;
}
// call the Web Service function
Label1.Text += MyService.HelloWorld() + "<br />";
}
output will be:- Hello World - Call Number: 1 Hello World - Call Number: 2 Hello World - Call Number: 3
Upvotes: 1
Reputation: 12448
A web service generally runs in a web application just like a web site, so you have access to all the same session functionality.
You can store data in the session using :
Session["FirstName"] = "Peter";
Session["LastName"] = "Parker";
Retreive it using:
ArrayList stockPicks = (ArrayList)Session["StockPicks"];
Upvotes: 1