目前关于REST 服务的话题越来越热,kbmmw 在5.0 里面开始支持rest。今天我就试一下kbmmw 的

rest 服务。闲话少说,开始。

老规矩,放上两个kbmMWServer1和 kbmMWHTTPSysServerTransport1两个控件。

设置kbmMWHTTPSysServerTransport1的server 属性。urls 属性默认是http://+:80/, 我们在这里就不改了。

因为我们后面采用的是samrtservice. 因此现在在主窗体里面不用再操心后面有什么服务要注册了。只需要一句话就

ok了。

procedure TForm2.Button1Click(Sender: TObject);
begin
kbmMWServer1.Active:=True;
end; procedure TForm2.FormCreate(Sender: TObject);
begin
kbmMWServer1.AutoRegisterServices;
end;

主窗体就ok 了。

接下来我们来建服务模块

选择这个smartservice

记住这里要填成你定义的这个服务名。然后一路点过去。

默认生成的代码如下:

type

  [kbmMW_Service('name:xalionservice, flags:[listed]')]
[kbmMW_Rest('path:/xalionservice')]
// Access to the service can be limited using the [kbmMW_Auth..] attribute.
// [kbmMW_Auth('role:[SomeRole,SomeOtherRole], grant:true')] TkbmMWCustomSmartService1 = class(TkbmMWCustomSmartService)
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
// HelloWorld function callable from both a regular client,
// due to the optional [kbmMW_Method] attribute,
// and from a REST client due to the optional [kbmMW_Rest] attribute.
// The access path to the function from a REST client (like a browser)+
// is in this case relative to the services path.
// In this example: http://.../xalionservice/helloworld
// Access to the function can be limited using the [kbmMW_Auth..] attribute.
// [kbmMW_Auth('role:[SomeRole,SomeOtherRole], grant:true')]
[kbmMW_Rest('method:get, path:helloworld')]
[kbmMW_Method]
function HelloWorld:string;
end; implementation uses kbmMWExceptions; {$R *.dfm} // Service definitions.
//--------------------- function TkbmMWCustomSmartService1.HelloWorld:string;
begin
Result:='Hello world';
end; initialization
TkbmMWRTTI.EnableRTTI(TkbmMWCustomSmartService1);
end.

这个代码比较简单,只是定义了很少的属性。

但是已经可以运行了。

直接在浏览器里面输入http://127.0.0.1/xalionservice/helloworld 就可以看到下图

好,最简单的rest 服务做好了,我们继续做更复杂的。

我们加一个输入字符串,然后回应

  [kbmMW_Method('EchoString')]       // 回应输入的串
[kbmMW_Rest('method:get, path: [ "echostring/{AString}","myechostring/{AString}" ]')]
[kbmMW_Auth('role:[SomeRole,SomeOtherRole], grant:true')]
function EchoString([kbmMW_Rest('value: "{AString}"')] const AString:string):string; end; implementation uses kbmMWExceptions; {$R *.dfm} // Service definitions.
//--------------------- function TkbmMWCustomSmartService1.EchoString(const AString: string): string;
begin
result:='你好!'+astring;
end;

在浏览器里面输入http://127.0.0.1/xalionservice/echostring/xalion

和我们想象的一样。

继续加入更复杂的

     [kbmMW_Method]
[kbmMW_Rest('method:get, path: "cal/addnumbers"')]
function AddNumbers([kbmMW_Rest('value: "$arg1", required: true')] const AValue1:integer;
[kbmMW_Rest('value: "$arg2", required: true')] const AValue2:integer;
[kbmMW_Arg(mwatRemoteLocation)] const ARemoteLocation:string):integer;
end; implementation uses kbmMWExceptions; {$R *.dfm} // Service definitions.
//--------------------- function TkbmMWCustomSmartService1.AddNumbers(const AValue1, AValue2: integer;
const ARemoteLocation: string): integer;
begin
Result:=AValue1+AValue2;
end;

浏览器里面可以输入http://127.0.0.1/xalionservice/cal/addnumbers?arg1=10&arg2=50

很简单吧.

下面再说一下,服务属性的常用参数,大家可以根据自己的需要改。

// server (optional) indicates name of TkbmMWServer instance to register service with. If missing will be registered with all server instances.

// name (optional) overrides service preferred name.
  // version (optional) overrides service version.
  // minInstances (optional) overrides services minInstances.
  // maxInstances (optional) overrides services maxInstances.
  // flags (optional). Array that can contain: [ listed,runrequireauth,listrequireauth,stateful,persistent,default ]
  // gatherStatistics (optional). Boolean value that can be on/off or true/false.
  // maxIdleTime (optional). Integer indicating max idle time in seconds before non stateful service instance is GC'ed.
  // maxIdleStatefulTime (optional). Integer indicating max idle time in seconds before stateful service instance is GC'ed.
  // timeout (optional). Integer indicating max allowed time of a request in seconds before service instance is GC'ed.
  // dontQueue (optional). Boolean indicating if requests should be queued or not if no instances of the service is available at time of request.
  [kbmMW_Service('name:SMARTDEMO, version:1.0, minInstances:32, maxInstances:128')]

上面做完了,那么如何通过这个REST 服务与前端的JS 显示库结合呢?

这个问题就留给各位同学研究吧。

kbmmw 5.0 中的REST 服务的更多相关文章

  1. ASP.NET Core 3.0 上的gRPC服务模板初体验(多图)

    早就听说ASP.NET Core 3.0中引入了gRPC的服务模板,正好趁着家里电脑刚做了新系统,然后装了VS2019的功夫来体验一把.同时记录体验的过程.如果你也想按照本文的步骤体验的话,那你得先安 ...

  2. 在 vSphere 5.x/6.0 中配置 Network Dump Collector 服务 (2002954)

    vmware KB: https://kb.vmware.com/s/article/2002954?lang=zh_CN 重点配置命令: 使用 vSphere Client 连接到 vCenter ...

  3. 避免在ASP.NET Core 3.0中为启动类注入服务

    本篇是如何升级到ASP.NET Core 3.0系列文章的第二篇. Part 1 - 将.NET Standard 2.0类库转换为.NET Core 3.0类库 Part 2 - IHostingE ...

  4. WCF学习之旅—WCF4.0中的简化配置功能(十五)

    六 WCF4.0中的简化配置功能 WCF4.0为了简化服务配置,提供了默认的终结点.绑定和服务行为.也就是说,在开发WCF服务程序的时候,即使我们不提供显示的 服务终结点,WCF框架也能为我们的服务提 ...

  5. 如何在springMVC 中对REST服务使用mockmvc 做测试

    如何在springMVC 中对REST服务使用mockmvc 做测试 博客分类: java 基础 springMVCmockMVC单元测试  spring 集成测试中对mock 的集成实在是太棒了!但 ...

  6. Android6.0中的权限

    Android6.0相比之前的Android版本有一个很大的不同点,就是动态的获取权限.之前我们需要什么权限只需要在Manifest文件中声明即可,在6.0中,又新增了运行时权限的动态检测. Andr ...

  7. Oracle几个基础配置问题:ORA-12154: TNS: 无法解析指定的连接标识符、ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务、ORA-12516 TNS监听程序找不到符合协议堆栈要求的可用处理程序

    问题1:ORA-12154: TNS: 无法解析指定的连接标识符 在一台服务器上部署了Oracle客户端,使用IP/SID的方式访问,老是报ORA-12154错误,而使用tnsnames访问却没有问题 ...

  8. ASP.NET MVC 中应用Windows服务以及Webservice服务开发分布式定时器

    ASP.NET MVC 中应用Windows服务以及Webservice服务开发分布式定时器一:闲谈一下:1.现在任务跟踪管理系统已经开发快要结束了,抽一点时间来写一下,想一想自己就有成就感啊!!  ...

  9. 如何在ubuntu中启用SSH服务

    如何在ubuntu14.04 中启用SSH服务 开篇科普:  SSH 为 Secure Shell 的缩写,由 IETF 的网络工作小组(Network Working Group)所制定:SSH 为 ...

随机推荐

  1. Linux下常用的编辑文件与保存命令

    打开文件: vi aaa.conf 编辑: i 编辑结束,按ESC 键 跳到命令模式,然后输入退出命令: :w (write)保存文件但不退出vi 编辑 :w! 强制保存,不退出vi 编辑 :w fi ...

  2. c++ STL模板(一)

    一.sort函数 1.头文件:#include < algorithm>: 2.它使用的排序方法是类似于快排的方法,时间复杂度为n*log2(n): 3.Sort函数有三个参数:(第三个参 ...

  3. 关于 No buffer space available (maximum connections reached?): connect 的处理

    一.问题: hudson一个应用打包部署一直不成功,检查报错 检查项目的JOB配置,开始以为是SVN的问题,但是重启SVN后问题一直存在 二.分析: TCP协议中,关闭TCP连接的是Server端(当 ...

  4. avoid

    avoid 英[əˈvɔɪd] 美[əˈvɔɪd] vt. 避开,避免,预防; [法] 使无效,撤销,废止; [例句]The pilots had to take emergency action t ...

  5. sqljdbc4.jar的安装

    自己项目环境(idea+jdk1.8+tomcat8),在搭建maven项目时,由于本地数据库是使用了sqlserver,所以需要项目与sqlserver之间建立连接,但是网上查的资料都说微软不允许以 ...

  6. java命令启动jacocoagent及生成报告

    启动jacocoagent: java -Xms1024m -Xmx2048m -XX:-UseGCOverheadLimit -Ddruid.keepAlive=true -javaagent:/h ...

  7. 线特征---LineMatching代码运行(五)

    [1]    https://github.com/dlut-dimt/LineMatching The code is based on Matlab.  https://github.com/ka ...

  8. 使用 gitbook 写东西

    会了markdown 不会用gitbook怎么可以呢 先安装 npm install gitbook -g npm install gitbook-cli -g cli使用代码是客户端的意思,要牢记 ...

  9. DOM系列基础知识

    DOM (Document Object Model) 即文档对象模型, 针对 HTML 和 XML 文档的 API (应用程序接口) .DOM 描绘了一个层次化的节点树,运行开发人员添加.移除和修改 ...

  10. PAT 1087 有多少不同的值(20)(STL-set代码)

    1087 有多少不同的值(20 分) 当自然数 n 依次取 1.2.3.--.N 时,算式 ⌊n/2⌋+⌊n/3⌋+⌊n/5⌋ 有多少个不同的值?(注:⌊x⌋ 为取整函数,表示不超过 x 的最大自然数 ...