In ASP. NET 2.0, server variables such as session and application can be used in webmethod.
I. Session
[Webmethod (enablesession = True )]
Public String Hello ()
{
Return "Hello," +Session ["User"];
}
[Webmethod (enablesession = False )]
Public String Hello1 ()
{
Return "Hello," +Session ["User"];
}
[Webmethod]
Public String Hello2 ()
{
Return "Hello," +Session ["User"];
}
"Enablesession" is the session state enabled for the XML Web Services method, and "true" is enabled. The default status is false.
The above three methods can be used for session variables. Note:
If the status is set to true, when the client accesses WS, the session variable can be not assigned, with the default value.
If the status is set to false, the client must assign values to the session variable before accessing ws. Otherwise, an error is returned.
II. Application [Webmethod]
Public String Hello3 ()
{
Return "Hello," +Application ["User"];
}
You do not need to set method labels when using application.