Original: WebService using session, application
In ASP. NET 2.0, the server variables of Session and application are already available in WebMethod.
First, Session[WebMethod (EnableSession= true)]
Public stringHello ()
{
return "Hello," + session[" user"];
}
[WebMethod (EnableSession= false)]
Public stringHello1 ()
{
return "Hello," + session[" user"];
}
[WebMethod]
Public stringHello2 ()
{
return "Hello," + session[" user"];
}
"EnableSession" enables session state for the XML Web services method, enabled to True. The default state is false.
The use of Session variables can be achieved in all three ways. But be aware that:
If the status is set to True, the client may not assign a value to the session variable when accessing WS, which has a default value.
If the status is set to False, the client must assign a value to the session variable before accessing WS, otherwise an error is given.
Second, application
[WebMethod]
Public stringHello3 ()
{
return "Hello," + application[ " User " ];
}
You do not need to set the method label when using application
WebService using session, application