MTS Tips

05 Oct 2000 19:54

When to use

Software requirements

MTS Explorer

Coding

Packages

 

When to use

Server Components

MTS greatly simplifies the development of COM server components.  All threading, security, pooling (object pooling not supported just yet), and transaction processing are handled by MTS.  The developer only has to code the business logic of the component.   If the server component needs to be accessed often, the component should be implemented as a singleton to avoid constantly creating and deleting an instance each time it is needed (but singletons have issues, so don't use them unless you know what the gotchas are).  MTS components have a timeout property that tells MTS to delete the instance after a specified idle time (in minutes).

The implementation details of a server component are hidden from the client.  The client will not know whether its call to CoCreateInstance will instantiate a normal COM object or an MTS COM component.  Also note that MTS components can not be aggregated since the client actually gets an object's proxy and not the object itself.


Software requirements

Windows 2000 or:
  • NT 4.0 Option Pack
  • NT 4.0 Service Pack 4   (you must install NT 4.0 Service Pack 4 again after installing NT 4.0 Option Pack)
  • Microsoft Management Console

WARNING: Do not use Win9x with MTS!  The current version of MTS has unstable distributed transaction operations on Win9x.


MTS Explorer

The MTS Explorer is basically a tool for configuring MTS components, controlling the operation of MTS, and creating packages.

Adding MTS Explorer to MMC

The Transaction Explorer is an MMC snap-in.  To load the snap-in...

  1. Click on "Console"
  2. Click on "Add/Remove Snap-in"
  3. In the "Standalone" tab, you should see a "Microsoft Transaction Server" folder to select and then click the "Add" button

Administering MTS on a remote compuer

You can administer MTS on other computers connected to your LAN.  Simply right-click on the "Computers" folder and select "New".  This is useful when you want tell the MTS on the remote computers which computer server components are located on.  For instance, you can tell MachineA to look for server components on MachineB.

ISSUE: how to automate these steps in an installation program?  This may require a manual setup.


Coding

  • Creating the project
  1. use the ATL COM AppWizard
  2. select DLL for server type (MTS components must beinproc servers because MTS decides when to load and unload the object)
  3. click on "Support MTS" (this will link your project with appropriate MTS DLLs which are only loaded when actually needed)
  • Creating the MTS COM component
  1. use the ATL Object Wizard
  2. select MS Transaction Server Component
  3. select "Dual" for interface type
  4. click the "Support IObject Control" and "Can be pooled" options
  1. Add the statement "DECLARE_CLASSFACTORY_SINGLETON(<class name>)" without the parenthesis into your COM object's header file in the class declaration.  Be sure to add the name of your class as the parameter of the macro statement.
  • IMPORTANT NOTES
    1. The context parameter of CoCreateInstance must be either CLSCTX_LOCAL_SERVER, CLSCTX_SERVER, or CLSCTX_ALL since a call to CoCreateInstance on an MTS component will actually launch an EXE (mtx.exe).
    2. Be sure to NOT set the Identity of a package to "Interactive User".  Be sure to specify a specific user.

Now you can simply implement your COM object as you would normally do.  After successfully building your inproc server, simply add it as a package under MTS and you're done!


Packages

  • Definition

A package is a grouping of components.  One or more COM objects can be added into a single package.

  1. start up Transaction Explorer in MMC
  2. right-click on the "Packages Installed" folder under "My Computer" and select "New->Package"
  3. click on "Create an empty package"
  4. name your package
  5. set the "Account" to "Interfactive User" and click "Finish"
  6. open the "Components" folder under your new package
  7. from Windows NT Explorer, locate and select the DLL of your component and drag it into your "Components" window of MMC
  • Remote Components

Through Transaction Explorer, you can set up a client on one machine to be able to access an MTS component from a separate remote machine by the following...

  1. you must share the folder on the machine that contains the component that you want to be able to remotely access
  2. right-click on the "Remote Components" folder under the computer that you want as a client and select "New->Remote Component"
  3. select the machine that has the actual component(s)
  4. select the appropriate package which should cause a list of components in the package to be listed
  5. select the appropriate component and click the "Add" button

Now any CoCreateInstance calls made from the client for that particular component will be launched on the server machine similar to DCOM.

ISSUE: how to automate these steps in an installation program?  This may require a manual setup.

MTS controls when an MTS component should be unloaded and deleted from memory after being unused for a certain amount of idle time.  This idle time can be set by simply right clicking on the package in Transaction Explorer and selecting the Advanced tab.   The timeout property is in minutes and can be set there.