Convert DCOM object to a method of COM object
After upgrading to SP2, based on the considering of Windows XP SP2 security features, I have recently started to transfer the original DCOM application to COM environment. The problems and solutions that have occurred during the transfer process will be introduced as follows, please refer to the family:
First, the structure of the original DCOM application:
I use the Delphi IDE's wizard to generate a remote data module (RDBDBSVR), and put into the data set controls such as Adodataset, AdoQuery, establish an interface method, external Export method interface, provide data query function for the client, which uses independent Running process external service mode. The client uses DCOMConnection to connect to this remote data module. In short, it is a standard C / S application created in Delphi.
It should be noted that when you design RDBDBSVR, in order to maintain future code reuse, where no references are referenced directly, some variables set in order to synchronize threads, I put them in a common variable unit. At the same time, I also try to use the way instead of using the Provider control to provide data for customers. It turns out that this design reduces the complexity of DCOM to COM object conversion, and it should be quite convenient.
At the client, I introduce the Iappserver interface of the remote data module by utility variables and references this common variable and calls the method in most of the code. That is, there is no direct reference to a particular remote data provider in the code.
Second, now we convert the server.
Before the DCOM object conversion to the COM object, I actually used a fact: it is Delphi whether it is RemoteDataMoudel or MTSDataMoudle, which implements the IappServer interface and is classified into the Borland DataNap Applacation Server Catlog. Therefore, whether the MTS object is not a DCOM object, when using the DCOMConnection control to find the remote data provider (Remote Data Provider), it will appear in the list.
(1) method one
1. Create a new Transactional Data Moudle with Delphi IDE and put it in a separate ActiveX DLL.
2. Open the remote data module in the original DCOM server, select all of the controls, and copy it into your newly created MTS data module so that the properties of all controls in your original remote data module are replicated. This step is to prepare for the next step by DCOM remote data module code.
3. Open the Type library editor, add the type library of the original DCOM server to the reference list, and change the new MTS data module's Parent Interface to the interface implemented in the remote data module in the DCOM server. Then refresh the type library.
4. At this point your MTS interface implementation unit, the interface declaration of the original DCOM remote data module will be automatically added and the framework of implementing the code is added.
TDEMO = Class (TMTSDataModule, Idemo)
Private
{Private Declarations}
protected
Class Procedure UpdateRegistry (Register: Boolean; Const ClassID, PROGID: STRING); OVERRIDE
/ / The following is the interface table of my original remote data module, Delphi automatically copies it into this unit, and generates a code framework
Procedure Findpersons (Const Name, UnitNo: WideString; Out Rdatan: Olevariant); SaFECALL;
Procedure getfieldsname (const tbname: widestring; out fdnames: olevariant);
SafeCall;
Procedure getLaborage (Const Personno: WideString; Out Records: Olevariant);
SafeCall;
PROCEDURE GETOTHERINFO (Const TableName, Personno: WideString)
......
public
{Public declarations}
END;
......
Procedure Tdemo.findpersons (Const Name, UnitNo: WideString)
OUT RDataSet: Olevariant;
Begin
END;
......
5. Now, return to the realization unit of the original DCOM remote data module, copy the specific implementation code of its method to this unit. And replace the class name of the original DCOM object in the copy code into the class name of the MTS object. At the same time, pay attention: If the original DOCM remote data module references the public unit (such as my own reference to the public variable unit), you also need to add the referenced public unit to the User list.
6, here, your MTS data module with the DCOM data module is fully implemented, compile and register the MTS object.
Third, the client:
Open your client application source code and open the list of DCOMConnection objects in the client data module, at this time, you will be able to see the MTS object appears in the list, select it, and recompile your customers. application. If you don't join the reference hard coding for ServerName in the client code, you will see that the client does not need any changes, and it is not a DCOM object in the COM environment at this time. MTS object. To confirm this, you can run DCMCNFG. In the Local Computer "Process" list, you will see that MTS is in cheerful rotation.
Fourth, pay attention to the problem:
1. The above method is to import the type library of the original DCOM application server into the MTS server and implement the method in the type library. Therefore, if you publish the newly generated MTS server component to other computers, and do not copy the original DCOM application server and register to the computer, put your client will receive the "Can't find the type library" error. prompt. The way to solve this problem is to copy the * .tlb file of the original DCOM application server to the computer and use Tregsvr.exe -t (Server) .tlb to register the type library on the computer (Server uses your original server name ). Alternatively, when editing the MTS object type library, directly reference the TLB file of the original server, and the TLB file is distributed with the MTS package in the division MTS object.
2, the above conversion is actually only on the relatively simple DCOM object. If your DCOM code is added to the backend database-related transaction support code, you must modify its code to use the transaction management function provided by MTS to give full play to the power of MTS resource management, transaction coordination, of course If your DCOM object does not use a thread model compatible with the MTS, your modification will be larger.
3. After converting into an MTS object, you can directly use the MTS role-based security feature to perform subtle control of your MTS security attribute, and do not add any code, of course, if your code is added to DCOM Special security settings, you may have to fine tune. However, COM will compatible with these security code. 4. After converting into an MTS object, it is recommended that you re-determine your COM's "Minimum Secure Restriction" property that occurs and your computer's firewall settings, so as not to stop working or "Reject Access".
Kunlun Inverters 2004-11-10 in Urumqi
I don't know why, I posted the picture in the article on 9CBS, I can't display correctly. If you can't see the picture, please enter my document area http://blog.9cbs.net/liangma, then view.