Soap & Web Service

Source: Internet
Author: User
The execution efficiency of web services is relatively low. Therefore, you should try to return all data at once when calling Web methods. you can also use the cache technology. the so-called cache technology means that when the same method is called within a period of time, the web method is not executed, but the result is obtained directly from the cache. in. the cacheduration feature can be used to modify the web method. [webmethod (description = "number of times this service has been accessed ",
Cacheduration = 60, messagename = "serviceusage")]
Public int serviceusage ()
{
// If the XML Web Service has not been accessed, initialize it to 1.
If (application ["myserviceusage"] = NULL)
{
Application ["myserviceusage"] = 1;
}
Else
{
// Increment the usage count.
Application ["myserviceusage"] = (INT) application ["myserviceusage"]) + 1;
} // Return the usage count.
Return (INT) application ["myserviceusage"];
} The code above indicates that the method is called within 60 seconds. The code is executed only for the first time, and the rest will only get results from the cache. the cache will be cleared after 60 seconds. in addition to cacheduration, you can also use cache classes. static int I = 0; [webmethod]
Public int test ()
{
I = I + 1;
If (httpcontext. Current. cache ["I"] = NULL)
{
Httpcontext. current. cache. add ("I", I, null, datetime. maxvalue, new timespan (6000), cacheitempriority. normal, null); // httpcontext. current. cache. add ("I", I, null, datetime. now. addseconds (6), timespan. zero, cacheitempriority. normal, null); this statement is acceptable.
}
Else
{
I = convert. toint32 (httpcontext. Current. cache ["I"]);
}
Return I;
} An object is added to the Cache during the first execution in the code above. The object will be released after 6 seconds. unlike cacheduration, even if an object already exists in the cache, the code in the method is still executed when the method is executed.

 

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.