NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Automatic Transactions and Web Services

ASP+ provides built-in support for creating and exposing Web Services — using a programming abstraction that is consistent and familiar to both ASP+ Web Forms and Visual Basic developers. The resulting model is scalable, extensible, and embraces HTTP, XML, SOAP, and SDL open Internet standards, among others. By supporting open standards, Web services can be accessed and consumed by any client or Internet-enabled device.

Like ASP+ Web Forms, ASP+ Web Services offers a developer the option to execute their code within the scope of an automatic transaction. A transaction ensures that all interactions with resource managers like SQL Servers, MSMQ Servers, Oracle Servers, and SNA Servers maintain the ACID properties required to run robust distributed applications.

You can declare an automatic transaction by using the custom enumeration property, Transaction, on the WebMethod metadata attribute of a WebMethod. The declaration begins a new transaction each time a client calls the WebMethod.

The following code fragment shows a service that exposes a single WebMethod, called DeleteDatabase. This WebMethod performs a database operation that is scoped within an automatic 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(
                          "Bar", "sa", "", "northwind");
    SQLDataSetCommand sqlAdapter1 = new SQLDataSetCommand(
                         "delete orders", sqlConn);
    SqlConn.Execute();
  }
}

Important

A transaction will begin only when the activating WebMethod, which is the method called from the client, has transaction metadata. If the activating WebMethod does not carry the appropriate transaction metadata, subsequent WebMethods can neither participate in an existing transaction nor begin a new transaction.