Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Upgrading Components That Use the com.ms.mtx Package

Visual Studio 2005

The classes in the com.ms.mtx package make Microsoft Transaction Server (MTS) functionality available to Java-language developers. The documentation in Visual J++ 6.0 and the Microsoft SDK for Java discusses these classes in detail. Visual J# does not support the com.ms.mtx package. While upgrading Visual J++ applications that use this package, it is recommended that you move to the corresponding classes in the .NET Framework System.EnterpriseServices namespace. The classes in System.EnterpriseServices provide functionality equivalent to the classes in the com.ms.mtx package.

The canonical form of writing MTS components in Visual J++ using the com.ms.mtx package is shown below:

public int transactMethod ()
{
    IObjectContext context;
    boolean success = false;
    IMtxComp mtxComp = null;

    // Obtain MTS context
    context = (IObjectContext) Mtx.GetObjectContext();

    // Obtain resources. For example, database connections
    // Use resources
    // Perform one piece of work for one client
    // Invoke other MTS components to do some of the work
    mtxComp = (IMtxComp) context.CreateInstance(CMtxComp.clsid, IMtxComp.iid);

    // all went well
    success = true;
    return 0;

    finally
    {
        // release resources
        if (success)
            context.SetComplete();
        else
            context.SetAbort();
    }
}

Some of the commonly used classes are com.ms.mtx.IObjectContext, com.ms.mtx.IGetContextProperties, com.ms.mtx.Context, and com.ms.mtx.MTx. The ContextUtil class in the System.EnterpriseServices namespace is a direct equivalent to the com.ms.mtx.IObjectContext and com.ms.mtx.Mtx classes. The other classes in the com.ms.mtx package like ISharedProperty, ISharedPropertyGroup, and ISharedPropertyGroupManager also have direct equivalents in the .NET Framework System.EnterpriseServices namespace.

The following example shows how a Visual J++ application will be upgraded to Visual J# using the classes in System.EnterpriseServices.

The Visual J++ 6.0 application

import com.ms.mtx.*;

/** @com.transaction(required) */
/** @com.register(clsid=E96931CC-DFDC-497C-B695-F9EC12F8F470) */
public class MtxServer
{
   public String transactMethod(String name)
   {
      String greeting = null;
      boolean complete = false;
      
      try
      {
         // This would probably be a database write in 
         // real world application code
         greeting = "Hello, " + name;
         complete = true;
      }

      finally 
      {
         IObjectContext ctx = MTx.GetObjectContext();
         if (complete)
         {
            ctx.SetComplete();
         }
         else
         {
            ctx.SetAbort();
         }
      }
      return greeting;
   }
}

After Upgrading to Visual J#

The code below illustrates how equivalent functionality can be achieved using the classes in the .NET Framework System.EnterpriseServices namespace. Methods of the public interfaces of the upgraded component must use types from the .NET Framework rather than Java-language types.

import System.EnterpriseServices.*;
import System.Runtime.InteropServices.*;

/** @attribute GuidAttribute("E96931CC-DFDC-497C-B695-F9EC12F8F470") */
/** @attribute TransactionAttribute(TransactionOption.Required) */
// The class has to extend System.EnterpriseServices.ServicedComponent
public class MtxServer extends ServicedComponent
{
   public String transactMethod(String name)
   {
      String greeting = null;
      boolean complete = false;

      try
      {
         // This would probably be a database write in 
         // real world application code
         greeting = "Hello, " + name;
         complete = true;
      }
      finally 
      {
         if (complete)
         {
            ContextUtil.SetComplete();
         }
         else
         {
            ContextUtil.SetAbort();
         }
      }
      return greeting;
   }
}

In some cases, the com.ms.mtx package is used in components that use the com.ms.asp package to retrieve the context object. In such cases, the .NET Framework System.Web.HttpContext class can be used to retrieve the Request or Response object.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft