Delphi EMS FireDAC:如何使用EMS将参数从客户端传递到服务器? [英] Delphi EMS FireDAC: How to pass parameter from client to server using EMS?

查看:246
本文介绍了Delphi EMS FireDAC:如何使用EMS将参数从客户端传递到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Delphi中使用 EMS (即:用于将来的iOS应用程序)来开发简单的客户端服务器应用程序。

I am working on the simple client server application using EMS (i.e: for future iOS application) in Delphi.

在客户端单元上,我有 EMSProvider EMSFireDACClient ,它们通过以下方式从数据库(MSSQL)提取数据数据源。

On the client unit, I have EMSProvider and EMSFireDACClient which fetches data from a Database (MSSQL) through a Datasource.

在服务器单元上,我有 FDConnection TFDQuery 处理我的数据库。到目前为止,一切正常。

On the server unit, I have FDConnection and TFDQuery which deals with my Database. So far everything is working fine.

问题:现在,我需要将一些参数从客户端传递到服务器,并获取结果数据。我应该如何使用 EMS EMS 中可用的任何功能或过程吗?

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.

预先感谢。

推荐答案

EMS呼叫就像REST呼叫。您可以在路径中直接传递进一步的URL参数(直接处理)-请参阅按ID获取项目的默认实现)以及作为额外的查询参数。这些在请求对象中。要传递它们,请在客户端中使用自定义端点。

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.

以下是更多信息:

服务器声明:

[ResourceSuffix('{item}')]
procedure GetItem(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);

服务器实现:

procedure TNotesResource1.GetItem(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);
var
  LItem: string;
begin
  LItem := ARequest.Params.Values['item'];
  ...

端点的客户端配置:

object BackendEndpointGetNote: TBackendEndpoint
  Provider = EMSProvider1
  Auth = BackendAuth1
  Params = <
    item
      Kind = pkURLSEGMENT
      name = 'item'
      Options = [poAutoCreated]
    end>
  Resource = 'Notes'
  ResourceSuffix = '{item}'
end

客户呼叫:

  BackendEndpointGetNote.Params.Items[0].Value := AID;
  BackendEndpointGetNote.Execute;

希望这会有所帮助。

这篇关于Delphi EMS FireDAC:如何使用EMS将参数从客户端传递到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆