WebMethod Attributes

Topics: Developer Forum, Project Management Forum, User Forum
Dec 31, 2007 at 4:41 PM
Edited Dec 31, 2007 at 4:59 PM
Today i received a very intersting request to make something similar for webservice with sharedcache like WebMethod Attributes:

How to: Use the WebMethod Attribute


(copy from msdn: http://msdn2.microsoft.com/en-us/library/byxd99hx(VS.80).aspx)

Attaching the WebMethod attribute to a Public method indicates that you want the method exposed as part of the XML Web service. You can also use the properties of this attribute to further configure the behavior of the XML Web service method. For more information, see Code Model for XML Web Services in Managed Code.

CacheDuration
The CacheDuration property of the WebMethod attribute enables caching of the results for an XML Web service method. ASP.NET will cache the results for each unique parameter set. The value of this property specifies how many seconds ASP.NET should cache the results. A value of zero disables the caching of results. Unless otherwise specified, the default value is zero. For more information, see WebMethodAttribute.CacheDuration Property.

To cache the results of an XML Web service method
Use the CacheDuration property of the WebMethod attribute, as shown below:

Visual Basic Copy Code
Public Class Service1
    Inherits System.Web.Services.WebService
    <System.Web.Services.WebMethod(CacheDuration:=60)> _
    Public Function ConvertTemperature(ByVal dFahrenheit As Double) _
                                       As Double
        ConvertTemperature = ((dFahrenheit - 32) * 5) / 9
    End Function
End Class

C# Copy Code
public class Service1 : System.Web.Services.WebService
{ 
    [System.Web.Services.WebMethod(CacheDuration=60)]
    public double ConvertTemperature(double dFahrenheit)
    {
       return ((dFahrenheit - 32) * 5) / 9;
    }
}
more information about this can be found on also on msdn: http://msdn2.microsoft.com/en-us/library/system.web.services.webmethodattribute.cacheduration(VS.80).aspx