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.
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.
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...
- Click on "Console"
- Click on "Add/Remove Snap-in"
- 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.
- use the ATL COM AppWizard
- select DLL for server type (MTS components must beinproc servers because MTS decides
when to load and unload the object)
- 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
- use the ATL Object Wizard
- select MS Transaction Server Component
- select "Dual" for interface type
- click the "Support IObject Control" and "Can be pooled" options
- 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
- 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).
- 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!
A package is a grouping of components. One or more COM objects can be added into
a single package.
- start up Transaction Explorer in MMC
- right-click on the "Packages Installed" folder under "My Computer"
and select "New->Package"
- click on "Create an empty package"
- name your package
- set the "Account" to "Interfactive User" and click
"Finish"
- open the "Components" folder under your new package
- from Windows NT Explorer, locate and select the DLL of your component and drag it into
your "Components" window of MMC
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...
- you must share the folder on the machine that contains the component that you want to be
able to remotely access
- right-click on the "Remote Components" folder under the computer that you want
as a client and select "New->Remote Component"
- select the machine that has the actual component(s)
- select the appropriate package which should cause a list of components in the package to
be listed
- 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.
|