Like ASP+ Web Forms, an ASP+ Web Service enables developers to execute their code within the context of a transaction. This will ensure that all interactions with NGWS-aware resources –-- SQL Servers, MSMQ Servers, Oracle Servers, SNA Servers, etc –-- maintain the ACID (atomic, consistent, isolated, durable) properties required to run robust distributed applications.
ASP+ Web Service developers can run in the context of a transaction using a custom enum property,Transaction, on the WebMethod metadata attribute of a method. This ensures that a new transaction is created whenever the method is activated from the client.
For example, the below web service exposes a single method, DeleteDatabase, that performs a database operation that is scoped within the context of a transaction:
<%@ WebService Language=”C#” %> using System; using System.Data; using System.Data.SQL; using System.Web.Services; public class TransactionStuff : WebService { [ WebMethod(Transaction=Transaction.Required) ] public void DeleteDatabase() { SQLConnection sqlConn = new SQLConnection("MyDB", "sa", "", "northwind"); SQLDataSetCommand sqlAdapter1 = new SQLDataSetCommand("delete orders", sqlConn); SqlConn.Execute(); } }
Important: Note that the transaction will only be created if the activating method (ie: the method called from the client) has the transaction metadata. It will not be created if the method on which the ASP+ Web Service is first created is not marked with the appropriate transaction metadata, even if a method that has the transaction metadata is subsequently invoked from it.