TsgcWSPServer_sgc › 事件 › OnRPC
当客户端在此服务器上调用 JSON-RPC 方法时触发。
property OnRPC: TsgcWSRPCEvent;
// TsgcWSRPCEvent = procedure(Connection: TsgcWSConnection; const ID, Method, Params: string) of object
—
针对每个携带非空 Id 且通过 RPCAuthentication 检查的调用触发。执行方法后,使用 RPCResult(成功)或 RPCError(失败)回复,并复用 ID 以便客户端关联响应。Params 是参数对象/数组的原始 JSON 文本。
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;