Distribuited Transactions between COM+ and API Framework 4.6

229 views Asked by At

how are you doing? ;)

Can you help me out with this situation? :

We currently have a COM+ Component with DTC (Distributed Transactions) and I need to migrate the transaction to a API .net (Framework 4.6) using this transaction to processes returning it back to COM+ to commmit/abort the transaction.

However, I was trying to pass it in the header as a parameter which is a guid generated from "mCTX.ContextInfo.GetActivityId" to use as a transaction into API (Framework 4.6) . But then the function needs a BASE64 token to validate de GetTransactionFromTransmitterPropagationToken function. Obviosly, to encode to base64 haven't work out to make the function regonize it as an function dtc. Any ideas how to make it operational?

I haven't found anything similar to study and apply, it's been a big challenge.

COM+ (Transaction Created)

Private mCTX               As ObjectContext

Set mCTX = GetObjectContext()
idChaveLog = mCTX.ContextInfo.GetActivityId


If Not mCTX Is Nothing Then mCTX.SetComplete

On Error:
 If Not mCTX Is Nothing Then mCTX.SetAbort
Example Guid Generated in idChaveLog: {38B5C47B-9E50-4AF5-9CB4-F5E6472B9FEB}

API .net (Framework 4.6) (Filter used to get TokenID to propagation of the transaction generated on COM+ (GUID)

public class EnlistToDistributedTransactionActionFilter : ActionFilterAttribute
    {
        private const string TransactionId = "TransactionToken";

        /// <summary>
        /// Retrieve a transaction propagation token, create a transaction scope and promote the current transaction to a distributed transaction.
        /// </summary>
        /// <param name="actionContext">The action context.</param>
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            if (actionContext.Request.Headers.Contains(TransactionId))
            {
                var values = actionContext.Request.Headers.GetValues(TransactionId);
                if (values != null && values.Any())
                {
                    byte[] transactionToken = Convert.FromBase64String(values.FirstOrDefault());
                    var transaction = TransactionInterop.GetTransactionFromTransmitterPropagationToken(transactionToken);
                    var transactionScope = new TransactionScope(transaction);

                    actionContext.Request.Properties.Add(TransactionId, transactionScope);
                }
            }
        }
1

There are 1 answers

1
Pratik 1020 On

You can try this

  1. In Windows search and type: "dcomcnfg" to bring up Component Services
  2. In the center pane, double click Computers, My Computer, then open the Distributed Transaction Coordinator folder
  3. Right click on Local DTC, and choose properties
  4. On the Security tab, under Security Settings, check the boxes for
  5. Network DTC Access and Enable XA Transactions
  6. Click OK to save changes