My custom delphi code-first RO/DA server needs to poll a REST end point and update the database with the contents (if changed).
I am implementing this by using a TTimer on the fServerDataModule. In the OnTimer event I am polling the end-point (in a TTask) to get a JSON string.
Then I am creating an instance of my data-service
//FRules is a string containing JSON from REST end-point
ClientID := ROMessage.ClientID;
fClassFactory := GetClassFactory('AquilaService');
fClassFactory.CreateInstance(ClientID, instance);
IAquilaService(instance).UpdateRulesFromJSON(fRules); //<-- need client access
In order to access the UpdateRulesFromJson method, I have to include my client-access interface unit (AquilaLibrary_Intf).
When I do this and compile the server, each time I try to access a data table on the client I get an exception "Error reading parameter aTableRequestInfoArray: Unexpected class found in stream; class “TableRequestInfo” does not descend from “TableRequestInfo”.
When I remove the reference to AquilaLibrary_Intf from the fServerDataModule it all works fine, but then I cannot utilise a reference to IAquilaService or any of its methods.
function intCreateSession: TGUID;
var
lSession: TROSession;
begin
Result := NewGuid;
lSession := ServerDataModule.SessionManager.CreateSession(Result);
CheckNotNull(lSession,'Session is null!');
ServerDataModule.SessionManager.ReleaseSession(lSession, true);
end;
ofc, it will work if you don’t have extra initialization in Login method
Thanks, but this doesn’t seem to be working for me:
clientID := NewGuid;
lSession := db_SessionManager.CreateSession(clientID);
try
// session not found on the line below still.
fAquilaService := LocalServiceAccessHelper_Acquire(clientID, 'AquilaService');
try
IAquilaService(fAquilaService).UpdateRulesFromJSON(fRules);
finally
LocalServiceAccessHelper_Release(clientID, 'AquilaService', fAquilaService);
end;
finally
db_SessionManager.ReleaseSession(lSession, true);
end;
It still gives me a Session not found error on the fAquilaService := LocalServiceAccessHelper.... line
The lSession object is valid, but in debugging I see no record created in my database’s session manager table (not sure if it should).
I do have some code in the SimpleLoginService.OnLogin event handler – but it’s only to check password hash, initialise the UserInfo object that is returned to the client and some logging of user activity - not something I would need on the server.
if Supports(fServiceInstance, IAquilaService , as1) then
as1.UpdateRulesFromJson(aRules)
else
raise Exception.Create('service does not support IAquilaService');