TsgcWSPServer_sgcEvents › OnRPC

OnRPC Event

Fires when a client invokes a JSON-RPC method on this server.

Syntax

property OnRPC: TsgcWSRPCEvent;
// TsgcWSRPCEvent = procedure(Connection: TsgcWSConnection; const ID, Method, Params: string) of object

Default Value

Remarks

Raised for every call that carries a non-empty Id and has passed the RPCAuthentication check. Execute the method and reply using RPCResult (success) or RPCError (failure), reusing ID so the client can correlate the response. Params is the raw JSON text of the parameter object/array.

Example

procedure TForm1.oProtocolRPC(Connection: TsgcWSConnection;
  const ID, Method, Params: string);
begin
  if Method = 'ping' then
    oProtocol.RPCResult(ID, '"pong"')
  else
    oProtocol.RPCError(ID, -32601, 'Method not found');
end;

Back to Events