zoukankan      html  css  js  c++  java
  • 一窥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;

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

  • 相关阅读:
    (转)Hadoop MapReduce链式实践--ChainReducer
    (转)Permission denied: win7下面eclipse上传本地文件到DFS && 运行M/R程序时出现的同样的错误解决方法
    为什么需要注册OCX控件?
    WPF插件开发:使用FrameworkElementAdapters时VS报错的问题
    C# semphore的使用
    C# int可以表示的最大值
    WCF客户端从服务器下载数据
    C# 读取WAV文件(详细)
    C#读取wav文件
    VEMap.DeleteAllShapeLayers 方法
  • 原文地址:https://www.cnblogs.com/xalion/p/6359035.html
Copyright © 2011-2022 走看看