How to call a service method which is defined in another service?

Hi

I want to call a service method which is defined in another service. For instance, I have one service definition unit (let’s call it unit interface_one.pas):

[ROService('interface_one')]
  TTest1 = class(TRORemoteDataModule)
    
  private
    
  public
    
    [ROServiceMethod]
    procedure CallOtherMethod;

I want to call (inside CallOtherMethod) this service method defined in unit interface_two.pas:

[ROService('interface_two')]
  TTest2 = class(TRORemoteDataModule)
    
  private
    
  public
    
    [ROServiceMethod]
    procedure DoSomething;

Is that possible?

Hi,

  • very simple way:
t2 := TTest2.Create(nil);
t2.DoSomething;
t2.Free;
  • if you need session support, you can pass session id via IROObjectActivation interface:
t2 := TTest2.Create(nil);
(t2 as IROObjectActivation).OnActivate(guid, nil);
t2.DoSomething;
(t2 as IROObjectActivation).OnDeactivate(guid);
t2.Free;

You can review LocalServiceAccess_Acquire/LocalServiceAccess_Release methods for more details but these methods are suitable for RODL-based services when you have defined interfaces like

TMegaDemoService = class(TRORemoteDataModule, IMegaDemoService)

Note: workaround with TTest2.Create means that standard class factory is used.
if you want to use other class factory, you should use something like

GetClassFactory(aName).CreateInstance(guid, l_service);

Thanks, it’s awesome to have a support service as good and efficient like yours