Client-side event does not get executed

Hello!

I am having trouble with client-side events.
I have an old-ish version of RO but I got it to compile from source for D11.
The last setup exe I have for RO is v. 10.0.0.1481 so I am assuming that’s the version I have.
This is my code server-side:

procedure TLoginService.AttemptLogin;
var
  LoginEvents: IROEventWriter<ILoginEvents>;
  Name, PW: String;
  LS: TLoginSuccessful;
  LD: TLoginDenied;
begin
  LoginEvents := EventRepository.GetWriter<ILoginEvents>(Session.SessionID);
    LoginEvents.ExcludeSender := False; 
   // Edited: I have noticed the ExcludeSender was after the event and put it before.
  // Regardless, still neither event  is working client-side.
  LoginEvents.Event.OnProvideCredentials(Name, PW);
  if ( Name = 'Admin' ) and ( Pw = mypw_constant ) then
  begin
    CreateSession;
    LS := TLoginSuccessful.Create;
    LS.Token := Session.SessionID.ToString;
    LoginEvents.Event.OnLoginResult(LS);
  end
  else begin
    LD := TLoginDenied.Create;
    LD.Reason := 'Bad user name or password';
    LoginEvents.Event.OnLoginResult(LD);
  end;
end;

The service is code-first and I have marked the interface with [ROEventSink].
Client side, I have the following code:

procedure TMainFrm.FormCreate(Sender: TObject);
begin
  ServerAccess := RemoteOfficeServerLibrary_ServerAccess.ServerAccess;
  RemoteService.Channel := ServerAccess.Channel;
  RemoteService.Message := ServerAccess.Message;
  RemoteEvents.Channel := ServerAccess.Channel;
  RemoteEvents.Message := ServerAccess.Message;
  RemoteEvents.ServiceName := 'Login';
  FLogin := ( RemoteService as ILogin );
  RemoteEvents.RegisterEventHandlers([EID_LoginEvents],[Self]);
  RemoteEvents.Active := True;
end;

procedure TMainFrm.OnLoginResult(const AResult: TLoginResult);
begin
  if AResult is TLoginSuccessful then
    FToken := TLoginSuccessful( AResult ).Token
  else
    MessageDlg(TLoginDenied( AResult ).Reason,TMsgDlgType.mtError, [TMsgDlgBtn.mbOK],0);
end;

procedure TMainFrm.OnProvideCredentials(var Name, Pw: UnicodeString);
begin
  Name := FUserName;
  Pw := FPass;
end;

Notably, the code doing the call is this:

procedure TMainFrm.AttemptLogin(UserName, Pass: String);
begin
  FUserName := UserName;
  FPass := Pass;
  FLogin.AttemptLogin;
end;

I checked and I also declared the ILoginEvents interface appropriately:
TMainFrm = class(TForm,ILoginEvents)

Neither event is called on the client side and I am not sure of what I am doing wrong.
I can see the login result classes in the RODL as well as the event sink if I connect to localhost:8099.
I have exhausted the ways this could be wrong.

Suggestions? I think I ticked all the boxes, but I clearly haven’t, it seems!

Cheers!

A

Okay, I stand corrected: it does get executed but the remote function does not wait for the actual execution which winds up being asynchronous. I want it to be synchronous, i.e. the code to wait for the event being executed before going forward.

Any way to do that?

Thank you!

Hi,

We support only server-side events, i.e. server sent it to client and forgot about it.
This means that event parameters will be used as read/only even it is declared as var. also events have to declared as procedures and not as functions.

Pls read Event Sinks and Server Callbacks for more details.

In your case, I’d suggest to pass parameters to AttemptLogin. You can pass them with encrypted way and decrypt on server-side or just use AES Envelope or SSL/TLS protocol.