Platform SDK: Transaction Server |
[This product will work only on Windows NT 4.0 versions and earlier. For Windows 2000 and later, see COM+ (Component Services).]
The Receipt component contains a single method, GetNextReceipt. The Receipt object itself doesn't maintain the value of the receipt number between calls. The Shared Property Manager maintains these values. The Receipt object calls a SharedProperty object to get a new receipt number.
You will also add code to the MoveMoney component to call the Receipt component.
To create the Receipt Component
Click here to see the code for the Receipt component
Click here to see the code for the MoveMoney component
By adding a new class module, you add a new COM component to this DLL. Therefore, you need to delete the existing components in the Microsoft Transaction Server Explorer and then install the new components.
To reinstall your components
To set the transaction attributes for your components
Note that the Receipt component is not transactional because the receipts are maintained as properties in memory and aren't durable.
When you run the Bank Client, select the MoveMoney button under Component. You should see the response Credit, balance is $ 1. (VB); Receipt No: #####.
The various object creation methods for Shared Property Manager objects are designed for simplified coding. If the object doesn't exist, it will be created. If it already exists, the object is returned. GetNextReceipt makes the following method call to access the shared property group manager:
Set spmMgr = CreateObject _ ("MTxSpm.SharedPropertyGroupManager.1")
This code works every time it is called. There is no need to check if the shared property group manager has already been created. Such behavior also ensures that only one instance of the SharedPropertyGroupManager object exists per server process.
For the SharedPropertyGroup and SharedProperty objects, a flag is returned to indicate whether the property group or property already exists. The following code shows how this flag is used to determine if the property needs to be initialized:
Set spmPropNextReceipt = _ spmGroup.CreateProperty("Next", bResult) ' Set the initial value of the SharedProperty to ' 0 if the SharedProperty didn't already exist. If bResult = False Then spmPropNextReceipt.Value = 0 End If
Access to shared properties is controlled through the CreatePropertyGroup method:
Set spmGroup = _ spmMgr.CreatePropertyGroup("Receipt", _ LockMethod, Process, bResult)
CreatePropertyGroup has two parameters, isolation mode and release mode. The isolation mode for the Receipt property group is set to LockMethod, which ensures that two instances of the Receipt object can't read or write to the same property during a call to GetNextReceipt. The release mode for the Receipt property group is set to Process, which maintains the property group until the server process is terminated.
See Also
Application Design Notes: Sharing State by Using the Shared Property Manager, SharedPropertyGroupManager object, CreateProperty methodasmthCreatePropertyvb, CreatePropertyGroup methodasmthCreatePropertyGroupvb