Attributes can help you polish your web service, and improve performance.
Web services are certainly quite useful... The .Net framework has some pretty nifty features that save you a lot of time. One such feature is the HTTP interface that most webservices will have. Simply open your favorite browser and browse to the location of the .asmx file. You will see a page that allows you to click on all public methods, which in turn brings up a page that allows you to fill in all arguments to said method.
A perhaps little know fact is that you can slightly customize that interface using WebMethodAttributes. The first attribute that you should always include is the Description attribute. It will print whatever text you include next to the method name... quite useful.
This is how you apply these attributes
VB.Net
<WebMethod(Description="this is the description")>
C#
[WebMethod(Description="this is the description")]
As you can see, not a whole lot of difference. But the advantage you gain is the ability for your users to figure out how to use your webservice right from the webservice itself.
There are of course other attributes that can be applied, each attribute is separated by a comma "[WebMethod(Description="",BufferResponse=true)]" Other attributes include.
- BufferResponse=true
The web service will stream the response (ie. dataset) by defaul. This will buffer that response in order to committ full resources to processing the method.
- CacheDuration=300
This will cache the output of the method for as many seconds as you specify... (300 = 5 minutes)
- EnableSession=false
This will turn off session management. Most web services do not even use sessions so it's best to turn it off and save your server some processing cycles.
- MessageName=""
The purpose of this attribute is to deal with operator overloading (methods with the same name, but different arguments). Since soap can't handle two methods having the same name, you can put a different name in messagename and that is what it will be published as.
Hope that helps someone