WebMethod attribute properties:-



Description:- Use to specify a description for the web service method.

BufferResponse:-
  1. This is a boolean property. Default is true. When this property is true, the response of the XML Web service method is not returned to the client until either the response is completely serialized or the buffer is full.
  2. On the other hand, when this property is false, the response of the XML Web service method is returned to the client as it is being serialized.
  3. In general, set BufferResponse to false, only when the XML Web service method returns large amounts of data. For smaller amounts of data, web service performance is better when BufferResponse is set to true.


CacheDuration:- Use this property, if you want to cache the results of a web service method. This is an integer property, and specifies the number of seconds that the response should be cached. The response is cached for each unique parameter.

How to add Description, CacheDuration in WebMethod shown in below:-

namespace CalculateWebServices
{
    [WebService(Namespace = "http://santosh-asp.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]


    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod(EnableSession = true,Description="Add two numbers", CacheDuration=20)]
        public int Add(int firstNumber, int secondNumber)
        {
            List<string> calculations;

            if (Session["CALCULATIONS"] == null)
            {
                calculations = new List<string>();
            }
            else
            {
                calculations = (List<string>)Session["CALCULATIONS"];
            }

            string strTransaction = firstNumber.ToString() + " + "
                + secondNumber.ToString()
                + " = " + (firstNumber + secondNumber).ToString();
            calculations.Add(strTransaction);
            Session["CALCULATIONS"] = calculations;

            return firstNumber + secondNumber;
        }

        [WebMethod(EnableSession = true,Description="Returns all the recent transaction")]
        public List<string> GetCalculations()
        {
            if (Session["CALCULATIONS"] == null)
            {
                List<string> calculations = new List<string>();
                calculations.Add("You have not performed any calculations");
                return calculations;
            }
            else
            {
                return (List<string>)Session["CALCULATIONS"];
            }
        }
    }
}