Transactions

The .NET Framework provides an integration between XML Web services and Microsoft DTC distributed transactions. You can cause a method that is exposed using the WebMethod attribute to start a DTC transaction using the Transaction property of the WebMethod attribute.

					[WebMethod(TransactionOption=TransactionOption.Required)]
public DataSet GetBookByTitle(string title)
{
    DataSet ds;
    SqlCommand cmd;
    SqlDataAdapter dsCmd;
    SqlParameter param;
    SqlConnection conn;
    ds=new DataSet();
    conn=new SqlConnection(
        "user id=sa;password=;initial
        catalog=DevDotNet;data source=localhost");
    cmd=new SqlCommand("GetBooksByTitle",conn);
    cmd.CommandType=CommandType.StoredProcedure;
    param=cmd.Parameters.Add(new
        SqlParameter("@Title",SqlDbType.NVarChar,255));
    param.Value=title;
    param.Direction=ParameterDirection.Input;
    try
    {
    // Open the connection and execute the Command
        conn.Open();
        dsCmd=new SqlDataAdapter();
        dsCmd.SelectCommand =cmd;
        dsCmd.Fill(ds,"Titles");
        return ds;
    }
    catch (Exception err)
    {
    // An error occurred, pass the exception up
      throw err;
    }
    finally
    {
    // Close the Connection
        if (conn.State == ConnectionState.Open)
            conn.Close();
    }
}

Using transactions in this manner will only coordinate a transaction involving multiple resource managers (say a database and an MSMQ message queue) from a single Web service. Microsoft, IBM, and BEA Systems are currently working on a specification called Web Services Transaction (WS-Transaction) that will allow you to coordinate a transaction between multiple XML Web services. See the following URL for more information: msdn.microsoft.com/library/default.asp?url=/library/en-us/dnglobspec/html/ws-transaction.asp.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.187.233