Speed up your WebService

.NET WebServices are always more an important part of my every day work: they permit you to build distributed infrastructure and are a good way to permit different systems to talk together.

One of the useful tricks to increase WebService's performances is to use some sort of caching. Lots of times a WebService will return always the same results over multiple calls, so in this scenario it's recommended to cache the data retrieved to speed up the communication.

When developing .NET XML Web services you can take advantage of the ASP.NET output cache by adding the CacheDuration attribute to your WebMethod declaration.

The CacheDuration parameter indicates the number of seconds to hold the response in the ASP.NET output cache. You can simply write a method like this:

<WebMethod(CacheDuration:=60)> _
Public Function SayMeSomething() As String
    Return "Hello Stefano, I'm your WebService!"
End Function

and the WebMethod response will be hold in the output cache for 60 seconds. The default value is 0, which means that no caching is enabled.

This tricks can help you to increase performances and decrease the delay for data retrieval, but there's a thing to remember however: when caching is enabled, all requests and responses are held in memory on the server for all the cache duration. If these requests or responses are very large, you could have problems on memory usage on the server.

Print | posted on Thursday, March 02, 2006 4:33 PM

Comments on this post

# re: Speed up your WebService

Requesting Gravatar...
There's another thing to remember too, and it is quite fundamental; the output cache settings you describe are only valid for HTTP GET requests, not HTTP POST requests.

See http://support.microsoft.com/default.aspx?scid=kb;en-us;318299
Left by Stuart Preston on Mar 02, 2006 9:07 PM

# re: Speed up your WebService

Requesting Gravatar...
Thanks for the precisation Stuart
Left by Stefano Demiliani on Mar 03, 2006 6:57 AM

Your comment:

 (will show your gravatar)
 
Please add 5 and 4 and type the answer here: