Practical Approach To ASP.NET Web Services - Part Four - Web Method Attribute Properties

In this article, we will see different properties of Web Method attribute. This chapter is in continuation of previous articles. You can visit my previous articles here.

  • Description
  • BufferResponse
  • CacheDuration

Description

So, what is this Description property? We use description property to specify the description for our Web Service Method. In our previous chapter example, we have implemented two methods, Add and GetCalculations.

ASP.NET
 
Now, none of these methods provide a description. So, let’s go with the example. Suppose, in Add method, I want to add a description. To achieve that, we must specify a description property.



Now, let’s view the page.

ASP.NET

The description for Add method is now displaying on this page.

BufferResponse

BufferResponse is a Boolean property. Default is True. When this property is True, the response of this XML Web service method is not returned to the client until either the response is completely serialized or the buffer is full.

On the other hand, when we set this property as false, the response of XML Web Service method is returned to the client as it is being serialized.

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. A response is cached for each unique parameter.

Now, let’s understand CacheDuration with an example.

ASP.NET

Here, every time we click on Add button, the same parameters are passed. So, there is no point in re-executing it because we are going to get the same response. It’s better to cache a response of the Web Service method to improve the performance of the application. So, we will be using the CacheDuration Property.



If we specify CacheDuration as 20, then the response of that Web Method will be cached for 20 secs. Now, let’s run the solution.

We got an output as shown below.

ASP.NET
 
If you click before 20 secs, it will not get added in your Recent calculation list. After only after 20 seconds of time, it will get added because we have specified CacheDuration Property as 20.

ASP.NET

Now, we will see it with different parameters.

ASP.NET