Library Zone Articles
External Articles
Byte Size

Discovery Zone Catalogue
Diary
Links
Bookstore
Interactive Zone Ask the Gurus
Discussion Groups
Newsletters
Feedback
Etc Cartoons
Humour
COMpetition
Advertising
Site Builder ASP Web Ring ASP Web Ring

Click here
The Developer's Resource & Community Site
COM XML ASP Java & Misc. NEW: VS.NET
International This Week Forums Author Central Find a Job

Developing A Simple MTS Server Component

The source code for this example is available as a zip file for download here.

To work with any of these samples you will need the following:

  • Microsoft Visual J++ ver 6.0
  • Windows NT 4.0 Options Pack

The ClickServer has an Increment() method. Clients call this method and pass in an integer argument. All this server component does is increment the value passed in and return it back to the client.

The Steps involved in developing the MTS Server component are:

  1. Create a new COM DLL project
  2. Add MTS aware code to the project's class
  3. Mark the class as COM/MTS-enabled
  4. Build the project
  5. Deploy the DLL into The Microsoft Transaction Server

Create a new COM DLL project

An MTS component should always be packaged as a DLL. Select New Project and from the File menu, choose the COM DLL project template in Visual J++. Name the project ClickServer.

Add MTS aware code to the project's class

Rename the default Class1.java to ClickServer.java in the Project Explorer and change the contents of the file to the following code:


import com.ms.mtx.*; 
public class ClickServer { 

 public int Increment(int value)  { 
  IObjectContext context = null; 
  boolean        success = false; 
  long           result  = -1; 

  try   { 
   // Get MTS context and set the return data 
   context = (IObjectContext) MTx.GetObjectContext(); 
   result = ++value; 
   success = true; 
  } 
  catch(Exception e){ success = false; } 
  finally   { 
   if(success) 
    context.SetComplete(); // No errors. Complete transaction. 
   else 
    context.SetAbort(); // Error occurred. Abort transaction. 
  } 
  return result; 
 } 

} 


Mark the class as COM/MTS-enabled

To deploy the class in MTS, you need to make it a COM/MTS class. You can easily make it one by right-clicking the mouse on the ClickServer class from the Class Outline tab and Selecting Class Properties. Mark the MTS Support as Enabled and say OK.

Mark the Class as COM/MTS enabled
Mark the Class as COM/MTS enabled

You will immediately notice that some code similar to this is added to the ClickServer class


/** 
* @com.register ( clsid=CF198348-CBB2-11D2-B9C7-006097A7D34F,
			typelib=CF198349-CBB2-11D2-B9C7-006097A7D34F ) 
* @com.transaction (required) 
*/ 

The final code looks like this:

ClickServer.java
import com.ms.mtx.*;

/**
* @com.register ( clsid=CF198348-CBB2-11D2-B9C7-006097A7D34F, typelib=CF198349-CBB2-11D2-B9C7-006097A7D34F )
* @com.transaction (required)
*/


public class ClickServer {

 public int Increment(int value)  {
  IObjectContext context = null;
  boolean        success = false;
  int            result  = -1;

  try   {
   // Get MTS context and set the return data
   context = (IObjectContext) MTx.GetObjectContext();
   result = ++value;
   success = true;
  }
  catch(Exception e)   {    success = false;   }
  finally   {
   if(success)
    context.SetComplete();
// No errors. Complete transaction.
   else
    context.SetAbort();
// Error occurred. Abort transaction.
  }
  return result;
 }

}
 
 

Build the project

Select the Build menu and Build the project. This creates an MTS component DLL called ClickServer.dll. This contains both the ClickServer.class and all the appropriate stub code so that the DLL can be registered and deployed in MTS.

Deploy the DLL into The Microsoft Transaction Server

Start up the MTS Explorer. Go to the computer you want to install your component on and select "Packages Installed". Right click and create a New empty Package called ClickServer. Select the newly created ClickServer package and create a New Component. Select the Component through the Browse button into MTS. (Make sure you Install New Component rather than Import Components...) The ClickServer MTS Server component is now deployed on MTS and is ready for client invocations.

Next page.....Developing the MTS Client


What do you think of this article?

Have your say about the article. You can make your point about the article by mailing [email protected] (If you haven't allready joined, you can join by going to https://www.onelist.com/community/dev-java).

You can also write a review. We will publish the best ones here on this article. Send your review to [email protected]. Please include the title of the article you are reviewing.

Further Reading

The MTS Series by Gopalan Suresh Raj:

Microsoft Transaction Server By Gopalan Suresh Raj.
Gopalans introductory article on Microsoft Transaction Server intorduces the basics to MTS, and leads in to the example articles included in the series.

Developing a Simple MTS Client Application By Gopalan Suresh Raj.
Part 2 of a two part example.

Developing The Bank Account IDL By Gopalan Suresh Raj.
A Three-Tier Architecture for a Bank Checking Account - Developing The Bank Account IDL is part 1 of a 3 part example.

MTS Server Component By Gopalan Suresh Raj.
A Three-Tier Architecture for a Bank Checking Account - MTS Server Component is the second part of this three part example.

MTS Client By Gopalan Suresh Raj.
A Three-Tier Architecture for a Bank Checking Account - MTS Server Component is the third part of this three part example.


Author: Gopalan Suresh Raj

You can meet Gopalan, and the other iDevResource authors in Author Central. Gopalan also maintains his own site at https://www.execpc.com/~gopalan/.

Contributors to iDevResource.com get their own site at Author Central. Why not write an article and become a member of the iDevResource community.

© Copyright 1997-2000 Gopalan Suresh Raj. Reproduced with Permission


Click here

Contribute to IDR:

To contribute an article to IDR, a click here.

To contact us at IDevResource.com, use our feedback form, or email us.

To comment on the site contact our webmaster.

Promoted by CyberSavvy UK - website promotion experts

All content © Copyright 2000 IDevResource.com, Disclaimer notice

WTL Introduction

Visit the IDR Forums

Java COM integration

Visit our NEW WTL Section

Code Project