DekGenius.com
[ Team LiB ] Previous Section Next Section

WebMethodAttribute

System.Web.Services (system.web.services.dll)sealed class

Use the WebMethodAttribute to mark all the methods that should be made available to web service clients. All methods marked with this attribute will be accessible automatically and will be included in the WSDL document (and the proxy class) that .NET generates. Methods that are not marked with this attribute will not visible or usable, even if they are public.

You can set various properties when you use this attribute. For example, the Description property contains a string of information about a web method and is used for automatically generated description documents and the Internet Explorer test page. CacheDuration specifies (in seconds) how long a response will be cached and reused for web method requests with identical parameter values. EnableSession allows you to configure whether session support is enabled for your web method. By default, a web service method will not be cached at all, and session support will not be enabled. The BufferResponse property is rarely used, as it only applies to HTTP requests. By default, BufferResponse is True, as responses are serialized to memory and transferred only when complete. This ensures best performance for small amounts of data. Note that if you disable response buffering, you will not be able to use the method in conjunction with a custom SOAP extension.

The MessageName property is used to add an alias to a method. This property is most commonly used with polymorphic (overloaded) methods, which must be given unique names, or "disambiguated," before you can use them as web methods. When adding overloaded methods, the original method should retain its name for compatibility with existing clients.

The TransactionOption property allows a web method to take part in a COM+ transaction. Due to the stateless nature of the HTTP protocol, web service methods can only participate as the root object in a transaction. This means that both System.EnterpriseServices.TransactionOption.RequiresNew and System.EnterpriseServices.TransactionOption.Required will have the same effect, causing the web method to start a new transaction when it is invoked. Other COM objects that require transactions can then be created and used by the web method. A transaction started in this way is committed automatically when the method ends, unless the method explicitly calls System.EnterpriseServices.ContextUtil.SetAbort( ) or an unhandled exception occurs.

To set a property of the WebMethodAttribute, specify it by name in the attribute declaration (as in [WebMethod(EnableSession = True)])

public sealed class WebMethodAttribute : Attribute {
// Public Constructors
   public WebMethodAttribute( );
   public WebMethodAttribute(bool enableSession);
   public WebMethodAttribute(bool enableSession, System.EnterpriseServices.TransactionOption transactionOption);
   public WebMethodAttribute(bool enableSession, System.EnterpriseServices.TransactionOption transactionOption, 
        int cacheDuration);
   public WebMethodAttribute(bool enableSession, System.EnterpriseServices.TransactionOption transactionOption, 
        int cacheDuration, bool bufferResponse);
// Public Instance Properties
   public bool BufferResponse{set; get; }
   public int CacheDuration{set; get; }
   public string Description{set; get; }
   public bool EnableSession{set; get; }
   public string MessageName{set; get; }
   public TransactionOption TransactionOption{set; get; }
}

Hierarchy

System.Object System.Attribute WebMethodAttribute

Returned By

System.Web.Services.Description.ProtocolReflector.MethodAttribute

Valid On

Method

    [ Team LiB ] Previous Section Next Section