问题
I am working on the simple client server application using EMS
(i.e: for future iOS application) in Delphi.
On the client unit, I have EMSProvider
and EMSFireDACClient
which fetches data from a Database (MSSQL) through a Datasource.
On the server unit, I have FDConnection
and TFDQuery
which deals with my Database. So far everything is working fine.
Question: Now I need to pass some parameters from client to the server and that fetches the result data. How should I do using EMS
? Any functions or procedures available in EMS
?
Regarding source code, everything was handled by corresponding components. So coding part is very less.
Thanks in advance.
回答1:
An EMS call is like a REST call. You can pass further URL parameters both in the path (handled directly) -- see the default implementation of getting items by ID) and as extra query params. Those are in the request object. To pass them, use a custom Endpoint in the client.
Here is some more info:
Server declaration:
[ResourceSuffix('{item}')]
procedure GetItem(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);
Server implementation:
procedure TNotesResource1.GetItem(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);
var
LItem: string;
begin
LItem := ARequest.Params.Values['item'];
...
Client configuration for endpoint:
object BackendEndpointGetNote: TBackendEndpoint
Provider = EMSProvider1
Auth = BackendAuth1
Params = <
item
Kind = pkURLSEGMENT
name = 'item'
Options = [poAutoCreated]
end>
Resource = 'Notes'
ResourceSuffix = '{item}'
end
Client call:
BackendEndpointGetNote.Params.Items[0].Value := AID;
BackendEndpointGetNote.Execute;
Hope this helps.
来源:https://stackoverflow.com/questions/26507557/delphi-ems-firedac-how-to-pass-parameter-from-client-to-server-using-ems