Use session, application in WebService

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.