|
The Developer's Resource & Community Site
|
Developing A Simple MTS Server Component
Author: Gopalan Suresh Raj
Date Submitted: January 26th 2000
Level of Difficulty: Advanced
Subjects Covered: Microsoft Transaction Server
Pre-required Reading: Microsoft Transaction Server
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:
- Create a new COM DLL project
- Add MTS aware code to the project's class
- Mark the class as COM/MTS-enabled
- Build the project
- 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
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.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: None
Developing a Simple MTS Client Application By Gopalan Suresh Raj.
Part 2 of a two part example.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server, Developing a Simple MTS Server Component
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.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server
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.
Author: Gopalan Suresh Raj
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server, Developing The Bank Account IDL
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
Date Submitted: Jan 26 2000
Level of Difficulty: Beginners / Intermediate
Subjects Covered: MTS
Pre-required Reading: Microsoft Transaction Server, Developing The Bank Account IDL, MTS Server Component
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
|