Scenario: An ASP+ WebMethod written in a NGWS runtime language (VB7) updates multiple databases. The managed page is hosted in an ASP+ Worker process.
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 developers and existing VB users. The resulting model is both scalable and extensible – and embraces open Internet standards (HTTP, XML, SOAP, SDL) so that it can be accessed and consumed from any client or Internet enabled device.
Like ASP+ Web Forms, ASP+ WebServices optionally enable developers to execute their code within the context of a MTS Transaction (for more information on the ASP+ Transaction Story, please see topics on ASP+ Transactions). This will ensure that all interactions with Resource managers – SQL Servers, MSMQ Servers, Oracle Servers, SNA Servers, etc – maintain the ACID (atomic, consistent, isolated, durable) properties required to run robust distributed applications.
WebService developers indicate that they wish to run in the context of a MTS transaction using a custom enum property – Transaction – on the WebMethod metadata attribute of a webmethod. This will ensure that a new MTS Transaction is created whenever the webmethod is activated from the client.
For example, the below web service exposes a single webmethod – “DeleteDatabase” – that performs a database operation that is scoped within the context of a MTS 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( "FooBar", "sa", "", "northwind"); SQLDataSetCommand sqlAdapter1 = new SQLDataSetCommand( "delete orders", sqlConn); SqlConn.Execute(); } }
Important: Note that the transaction will only be created if the activating webmethod (ie: the method called from the client) has the transaction metadata. It will not be created if the webmethod on which the webservice 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).