Click here to Skip to main content
12,292,585 members (69,614 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

9.5K views
2 bookmarked
Posted

ASP.Net Web Services – Different attribute properties of a WebMethod

, 20 Aug 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
CodeProject In the last blog post, we have discussed about how to use session state in a  web service. In this article we will go over different WebMethod attribute properties like Description, BufferResponse and CacheDuration. This is continuation of the previous article. So please go through that

In the last blog post, we have discussed about how to use session state in a  web service. In this article we will go over different WebMethod attribute properties like Description, BufferResponse and CacheDuration.

This is continuation of the previous article. So please go through that before proceeding this article to get a clear idea. You can read that article here.

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

Let’s understand this property with an example. We have already implemented 2 methods within the CalculatorWebService – Add and GetCalculations. At the moment, none of these methods display any description.

WebServices1

We want to associate some description with the Add method. To achieve this, specify Description property with the WebMethod.

WebServices2

Let’s view the web service in a browser. Notice that the description we have specified is displayed with the method.

WebServices3

BufferResponse – This is a boolean property whose default value 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. 

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.

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.

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

Let’s understand the CacheDuration property with an example. Let’s view the current webform in a browser. At the moment, when we click on Add button, each time the web service method will be processed and response will be returned. Even if we send same parameters, the web service method will be executed and the response will be sent back.

WebServices4

But when we send the same parameters, there is no point in re-executing it. So it is better to cache the response of the web service method to improve the performance of the application. Use CacheDuration property for this. If we specify CacheDuration property to say 20, then the response of the method will be cached for 20 seconds.

WebServices5

Build the web service and Update Service Reference. This process will regenerate the proxy class.

WebServices6

Now view the webform in a browser. For the first time, if we click on Add method with some parameters, the web service method will be processed and the result should be cached for 20 seconds. If we leave the parameters as same and click on Add method again, if we are within the 20 seconds, the web service method will not be processed. Instead, the response which is stored in the cache will be returned to the client.

WebServices7

On the other hand, if the 20 seconds are elapsed, then the web method will be reprocessed and the response will be cached for another 20 seconds.

WebServices8

But if we change the parameters and click on Add method, since these are different parameters, a separate response will be cached.

WebServices9

Reference: Arun Ramachandran (http://BestTEchnologyBlog.Com)


License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Arun Ramachandran India
Software Developer
India India
Arun Ramachandran is a Software Engineer having hands on experience in different Microsoft Technologies who is presently working in Experion Technologies, India. He has written over 95 articles on the subject on his blog at http://BestTEchnologyBlog.com. Along with 3 years of hands on experience he holds a Master of Computer Applications degree from Cochin University of Science & Technology (CUSAT).

You may also be interested in...

Comments and Discussions

 
QuestionWhy still asmx? Pin
aSarafian20-Aug-14 20:47
memberaSarafian20-Aug-14 20:47 
AnswerRe: Why still asmx? Pin
thewazz25-Aug-14 9:22
memberthewazz25-Aug-14 9:22 
GeneralRe: Why still asmx? Pin
aSarafian25-Aug-14 11:30
memberaSarafian25-Aug-14 11:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160518.1 | Last Updated 21 Aug 2014
Article Copyright 2014 by Arun Ramachandran India
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid