一窥kbmmw中的 smart service

在kbmmw 的新版中(还没有发布),将会有一个叫做smart service 的服务。这种服务的属性基于服务器端,
并且可以自动注册服务名,下面就是一个简单例子代码。这个服务里面有有三个发布的函数:echostring,
EchoReversedString和AddNumbers。这些函数使用一些声明变量,包括“魔法”参数变量,以便访问不同的
客户端标识值。


 [kbmMW_Service('SMARTDEMO')]
  TkbmMWCustomService2 = class(TkbmMWCustomSmartService)
  private
  protected
  public
     [kbmMW_Method]
     function EchoString(const AString:string):string;

     [kbmMW_Method('EchoReversedString')]
     function ReverseString(const AString:string;
                         [kbmMW_Arg(mwatClientIdentity)]
                         const AClientIdentity:TkbmMWClientIdentity
                           ):string;

     [kbmMW_Method]
     function AddNumbers(const AValue1,AValue2:integer;
                         [kbmMW_Arg(mwatRemoteLocation)]
                         const ARemoteLocation:string
                        ):integer;
  end;

...
function TkbmMWCustomService2.EchoString(const AString:string):string;
begin
     Result:=AString;
end;

function TkbmMWCustomService2.ReverseString(const AString:string;
         const AClientIdentity:TkbmMWClientIdentity):string;
begin
     Result:=StrUtils.ReverseString(AString);
end;

function TkbmMWCustomService2.AddNumbers(const AValue1,AValue2:integer;
         const ARemoteLocation:string):integer;
begin
     Result:=AValue1+AValue2;

     // ARemoveLocation contains the reported remote location
     // for the client.
end;

initialization
  // Make sure that RTTI is produced for the service class.
  TkbmMWRTTI.EnableRTTI(TkbmMWCustomService2);

 

以上代码毫无疑问可以执行,但是最理想的是如何让他非常方便的增加新的函数,并且不用繁琐的加入
注册代码,并且让客户端访问。
可以通过调用kbmMWServer1.AutoRegisterServices来自动注册kbmMW_Service中定义的服务。

没有使用kbmMW_Arg绑定的声明自动的被看作声明值,并接受调用者传来的值。

例如
[kbmMW_Method] function EchoString(const AString:string):string; 与一下代码相同 [kbmMW_Method] function EchoString([kbmMW_Arg] const AString:string):string; 与一下代码也相同 [kbmMW_Method] function EchoString([kbmMW_Arg(mwatValue)] const AString:string ):string; 在客户端调用时的代码就如下:

    s:=client.Request('SMARTDEMO','','echostring',['abc']);
     s:=client.Request('SMARTDEMO','','EchoReversedString',['abc']);
     i:=client.Request('SMARTDEMO','','addnumbers',[10,20]);

还有更方便的客户端调用方法

procedure TForm1.Button1Click(Sender: TObject);
var
   c:TkbmMWSmartClient;
   s:string;
   i:integer;
begin
     // New smart client.
     c:=TkbmMWSmartClientFactory.GetClient(Transport,'SMARTDEMO');
     s:=c.EchoString('abc');
     s:=c.EchoReversedString('abc');
     i:=c.AddNumbers(34,7);

     // Traditional client.
     s:=client.Request('SMARTDEMO','','echostring',['abc']);
     s:=client.Request('SMARTDEMO','','EchoReversedString',['abc']);
     i:=client.Request('SMARTDEMO','','addnumbers',[10,20]);
end;

由于目前新版还没有发布,目前只有这些内容。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值