Wrapping each and every RemObjects and DataAbstract Service Method Call

Hello everybody
I have to find a way to wrap each and every RemObjects and DataAbstract service method call in order to apply some kind of generic business logic which will apply on every call. I have found Hooks like OnActivate and OnDeactivate on the TRORemoteDateModule, yet those are being called once per DataModule lifecycle and not once per service call.

I need to do something like this…

procedure MyClass.MyMostLikelyOverridenUnknownMethod;
var
State: TSomeState;
begin
State := TSomeState.Create;

// I somehow need to make that state accessible to the service method itself
// but by parameter is not going to work since this would change its signature…
OriginalServiceMethodDefinedWithinTheRODL;

if State.WhatEver then
raise Exception.Create(‘sdf’);
end;

P.S.
I suppose I can do all this by OnActivate and OnDeactivate and member variables of the Service, but this works only as long as the service instantiation strategy creates a new Service instance upon each and every call…

Best regards
Francois

you can use HTTPServer.OnCustomResponseEvent event as described at Using OnCustomResponseEvent in a ROSDK Server

Note: you may need to write your exception into stream manually like

MyException := Exception.Create(‘sdf’);
aResponseStream.Size := 0;
lMessage.InitializeExceptionMessage(aTransport, '', lMessage.InterfaceName, lMessage.MessageName);
lMessage.WriteException(aResponseStream, MyException);