Calling a service method from inside the server with Code-First?

Hi,

I’m converting my project to code-first, so based on .rodl I had the server-side interfaces and to call a method from another service (example below), now, how do I do this using code-first model?

function TFirstService.GetServerTime: DateTime;
var
cf: IROClassFactory;
instance: IInterface;
objactivation:IROObjectActivation;
begin
cf:=GetClassFactory(‘SecondService’);
cf.CreateInstance(ClientID, instance);

if Supports(instance, IROObjectActivation, objactivation) then
begin
objactivation.OnActivate(ClientID, nil);
end;

Result := (instance as ISecondService).GetServerTime();

if Supports(instance, IROObjectActivation, objactivation) then
begin
objactivation.OnDeactivate(ClientId);
end;

instance := nil;
end;

Best Rergads,

Hi,

you can use code like

function TFirstService.GetServerTime: DateTime;
var
  instance: IInterface;
  objactivation:IROObjectActivation;
begin
  instance := TSecondService.Create(nil);

  if Supports(instance, IROObjectActivation, objactivation) then
    objactivation.OnActivate(ClientID, nil);

  Result := (instance as ISecondService).GetServerTime();

  if Supports(instance, IROObjectActivation, objactivation) then
   objactivation.OnDeactivate(ClientId);

  instance := nil;
end;

HI,

I have two doubts about this:

  • In order to create the object TSecondService it would be necessary for the TFirstService service to know the implementation of TSecondService (uses SecondService_Impl)? In my opnion this can generate some problems, or no?

  • In the line “Result: = (instance as ISecondService) .GetServerTime ();” In this case, the ISecondService is the interface of the SecondService_Impl service, so, I would have to make use of the “SecondService_Intf” service interface ??? that is, would I use the interface again?

Regards,

this won’t generate any problems. and yes, it should.

ah, yes.
in CodeFirst, you haven’t ISecondService so you can use service instance itself:

function TFirstService.GetServerTime: DateTime;
var
  instance: IInterface;
  service: TSecondService;
  objactivation:IROObjectActivation;
begin
  service := TSecondService.Create(nil);
  instance := service;

  if Supports(instance, IROObjectActivation, objactivation) then begin
    objactivation.OnActivate(ClientID, nil);
    objactivation := nil;
  end;

  Result := service.GetServerTime();

  if Supports(instance, IROObjectActivation, objactivation) then begin
   objactivation.OnDeactivate(ClientId);
   objactivation := nil;
  end;

  instance := nil;
end;

I tried this method, it seems works . As Default SecondService 's GetServerTime is Protected. It cant be used. I change the protected memebr all to to public. is It ok? Any risk?

Hi,

No any risk because only you have access to server-side sources.
if you like, you can introduce a new interface that will contain that method.