简体   繁体   English

Delphi EMS FireDAC:如何使用EMS将参数从客户端传递到服务器?

[英]Delphi EMS FireDAC: How to pass parameter from client to server using EMS?

I am working on the simple client server application using EMS (ie: for future iOS application) in Delphi. 我正在使用Delphi中的EMS (即:用于未来的iOS应用程序)处理简单的客户端服务器应用程序。

On the client unit, I have EMSProvider and EMSFireDACClient which fetches data from a Database (MSSQL) through a Datasource. 在客户端单元上,我有EMSProviderEMSFireDACClient ,它通过数据源从数据库(MSSQL)获取数据。

On the server unit, I have FDConnection and TFDQuery which deals with my Database. 在服务器单元上,我有FDConnectionTFDQuery来处理我的数据库。 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 ? 我该怎么办EMS Any functions or procedures available in EMS ? EMS可用的任何功能或程序?

Regarding source code, everything was handled by corresponding components. 关于源代码,一切都由相应的组件处理。 So coding part is very less. 因此编码部分非常少。

Thanks in advance. 提前致谢。

An EMS call is like a REST call. EMS调用就像一个REST调用。 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. 您可以在路径中传递更多URL参数(直接处理) - 请参阅按ID获取项目的默认实现)以及额外的查询参数。 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. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM