Hi
If our requirement is to fetch the same data again and again from database, then we can use caching concept in web service to increasing the performance and avoid the unnecessary hit to database.
Syntax for Caching in web service
[WebMethod(CacheDuration = 5)]
Where 5 is time duration in second.
Complete Syntax is like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;///
/// Summary description for TestCaching
///[WebService(Namespace = “http://tempuri.org/”)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class TestCaching : System.Web.Services.WebService {//This syntax is used for cache in webservice
[WebMethod(CacheDuration = 5)]
public string GetServiceTime()
{
return DateTime.Now.ToString();
}}