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.