Export (0) Print
Expand All

WebMethodAttribute Constructor (Boolean, TransactionOption, Int32)

Initializes a new instance of the WebMethodAttribute class.

Namespace:  System.Web.Services
Assembly:  System.Web.Services (in System.Web.Services.dll)

'Declaration
Public Sub New ( _
	enableSession As Boolean, _
	transactionOption As TransactionOption, _
	cacheDuration As Integer _
)

Parameters

enableSession
Type: System.Boolean

Initializes whether session state is enabled for the XML Web service method.

transactionOption
Type: System.EnterpriseServices.TransactionOption

Initializes the transaction support of an XML Web service method.

cacheDuration
Type: System.Int32

Initializes the number of seconds the response is cached.

A web service call can only be the root of a transaction, due to the stateless nature of the HTTP protocol. This means that the following two settings are equivalent, with each call creating a new transaction:

[WebMethod(TransactionOption = TransactionOption.Required)]
[WebMethod(TransactionOption = TransactionOption.RequiresNew)]

It also means that all the following settings are equivalent; meaning no transaction support:

[WebMethod] // TransactionOption.Disabled is the default
[WebMethod(TransactionOption = TransactionOption.Disabled)]
[WebMethod(TransactionOption = Transaction.NotSupported)]
[WebMethod(TransactionOption = Transaction.Supported)]

<%@ WebService Language="VB" Class="Counter" %>
<%@ assembly name="System.EnterpriseServices,Version=1.0.3300.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a" %>

Imports System.Web.Services
Imports System
Imports System.Web
Imports System.EnterpriseServices

Public Class Counter
    Inherits WebService  

    <WebMethod(true,TransactionOption.NotSupported,60)> _
    Public Function ServiceUsage() As Integer

        ' If the XML Web service has not been accessed, initialize it to 1.
        If Application("MyServiceUsage") Is Nothing Then
            Application("MyServiceUsage") = 1
        Else
            ' Increment the usage count.
            Application("MyServiceUsage") = CInt(Application("MyServiceUsage")) + 1
        End If

        ' Return the usage count.
        Return CInt(Application("MyServiceUsage"))
    End Function
End Class

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft