TsgcWSPServer_sgc › Eventi › OnRPC
Viene attivato quando un client invoca un metodo JSON-RPC su questo server.
property OnRPC: TsgcWSRPCEvent;
// TsgcWSRPCEvent = procedure(Connection: TsgcWSConnection; const ID, Method, Params: string) of object
—
Generato per ogni chiamata che contiene un Id non vuoto e ha superato il controllo RPCAuthentication. Eseguire il metodo e rispondere usando RPCResult (successo) o RPCError (errore), riutilizzando ID affinché il client possa correlare la risposta. Params è il testo JSON grezzo dell'oggetto/array dei parametri.
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;