AspNet.sk     Diskusné fóra     Vitajte v QuickStarts     ASP.NET     Silverlight     Ako môžem...? (en)     Class prehliadač Príklady chcem v ...   
Menu
Skip Navigation Links.

How Do I...? Common Tasks QuickStart Tutorial

How Do I...Use System.Transactions with EnterpriseServices Transactions?

System.Transactions provides functionality that allows interoperability with EnterpriseServices transactions. This sample will show how to use BYOT (Bring Your Own Transactions) with System.Transactions.

What is BYOT?
BYOT allows a component to be created with, or to inherit, an external transaction. That is, a component that does not already have an associated transaction can acquire a transaction. This is done by setting an arbitrary pre-existing transaction as the transaction property of a new component's context. In this case this is the transactions started with System.Transactions.

Convert the transaction:
Because it is necessary to use the BYOT functionality provided by the System.EnterpriseServices namespace, you must first convert the current transaction to be of the System.EnterpriseServices.Itransaction type. This can be done by the static TransactionInterop.GetDtcTransaction method as follows.


	Dim estx As System.EnterpriseServices.ITransaction
	estx = CType(TransactionInterop.GetDtcTransaction(Transaction.Current), System.EnterpriseServices.ITransaction)
VB

Associate a component with the transaction:
You can use the CreateWithTransaction method of the System.EnterpriseServices.BYOT class to do the actual work. In this case, an object, SvcComp, inheriting from System.EnterpriseServices.ServicedComponent will receive a reference to the requested transaction.


	Dim sc As SvcComp = New SvcComp
	System.EnterpriseServices.BYOT.CreateWithTransaction(estx, sc.GetType)
VB

Obtain context information for the component:
Next, the System.EnterpriseServices.ContextUtil class is used to obtain information about the context of the object that inherits this transaction. Specifically, the sample must determine the GUID of the current transaction, and whether the current context is transactional. The following properties are used to obtain this information.


	Console.WriteLine("IsInTransaction   {0}", ContextUtil.IsInTransaction)
	Console.WriteLine("TransactionId     {0}", ContextUtil.TransactionId)
VB

Here is a full example:

[This sample can be found at H:\Home\WU_000036_efe47225c86ca62f325a01d8519bc002\Webs\aspnet.sk\quickstarts\QuickStartv20\howto\samples\Transactions\byot
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]




Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.


Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright © 2005 Microsoft Corporation. All rights reserved.
Preklad do slovenského jazyka - Copyright © 2005 - 2007 www.aspnet.sk, www.qsh.sk
Pošlite komentár k tejto stránke
Copyright © 2002 - 2008 Chastia, spol. s r. o., Igor Stanek, Designed by Lacino
Portál je hostovaný na serveroch firmy Quantasoft - www.qsh.sk.