使用delphi 10.2 开发linux 上的webservice

简介: 前几天做了linux下apache的开发,今天做一个linux 下的webservice ,以供客户端调用。 闲话少说,直接干。 新建一个工程。选other...,选择如图。 继续输入服务名 然后就生成对应的单元。

前几天做了linux下apache的开发,今天做一个linux 下的webservice ,以供客户端调用。

闲话少说,直接干。

新建一个工程。选other...,选择如图。

继续输入服务名

然后就生成对应的单元。

 增加linux 平台。

 

完善对应的单元代码

{ Invokable implementation File for Txaliontest which implements Ixaliontest }

unit xaliontestImpl;

interface

uses Soap.InvokeRegistry, System.Types, Soap.XSBuiltIns, xaliontestIntf;

type

  { Txaliontest }
  Txaliontest = class(TInvokableClass, Ixaliontest)
  public

    function echoname(const Value:string):string; stdcall;
    function sumall(const Value:integer):integer; stdcall;

  end;

implementation


{ Txaliontest }

function Txaliontest.echoname(const Value: string): string;
begin
   result:='你好'+value;
end;

function Txaliontest.sumall(const Value: integer): integer;
var
  i:integer;
  isumall:integer;
begin
  isumall:=0;
  for i := 1 to value do
   isumall:=isumall+i;

  result:=isumall;
end;

initialization
{ Invokable classes must be registered }
   InvRegistry.RegisterInvokableClass(Txaliontest);
end.
{ Invokable interface Ixaliontest }

unit xaliontestIntf;

interface

uses Soap.InvokeRegistry, System.Types, Soap.XSBuiltIns;

type

  { Invokable interfaces must derive from IInvokable }
  Ixaliontest = interface(IInvokable)
  ['{20590E4A-BF8C-41AE-A630-94D2DD38EEE1}']

    { Methods of Invokable interface must not use the default }
    { calling convention; stdcall is recommended }
      function echoname(const Value:string):string; stdcall;
    function sumall(const Value:integer):integer; stdcall;
  end;

implementation

initialization
  { Invokable interfaces must be registered }
  InvRegistry.RegisterInterface(TypeInfo(Ixaliontest));

end.

编译本工程。

哎呀,怎么出错了?

不要害怕,这是因为linux 上apache的引用没有加入。我们确认apache 已经在linux上安装成功。

那么我们在IDE 里面处理一下。

记住设以上的地方为True, 允许未定义的引用。

现在重新编译

哈哈,OK 了

现在的任务就是在发布这个apache 模块。

这一块的内容请参照前面的文章。

配置文件如图:

 

 

 

启动apache.

 在浏览器里面输入对应的地址,就可以显示webservice 的接口信息了。

 

 好了,服务端搞定了。我们做一个客户端来调用一下这个服务。

直接建一个vcl application .

然后选择WDSL 导入器。

 

输入对应的地址。

 系统会生成对应的接口文件

// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL     : http://192.168.1.66/xalionws/wsdl/Ixaliontest
// Encoding : utf-8
// Version  : 1.0
// (2017-4-8 21:33:51 - - $Rev: 90173 $)
// ************************************************************************ //

unit Ixaliontest1;

interface

uses Soap.InvokeRegistry, Soap.SOAPHTTPClient, System.Types, Soap.XSBuiltIns;

type

  // ************************************************************************ //
  // The following types, referred to in the WSDL document are not being represented
  // in this file. They are either aliases[@] of other types represented or were referred
  // to but never[!] declared in the document. The types from the latter category
  // typically map to predefined/known XML or Embarcadero types; however, they could also 
  // indicate incorrect WSDL documents that failed to declare or import a schema type.
  // ************************************************************************ //
  // !:int             - "http://www.w3.org/2001/XMLSchema"[]
  // !:string          - "http://www.w3.org/2001/XMLSchema"[]


  // ************************************************************************ //
  // Namespace : urn:xaliontestIntf-Ixaliontest
  // soapAction: urn:xaliontestIntf-Ixaliontest#%operationName%
  // transport : http://schemas.xmlsoap.org/soap/http
  // style     : rpc
  // use       : encoded
  // binding   : Ixaliontestbinding
  // service   : Ixaliontestservice
  // port      : IxaliontestPort
  // URL       : http://192.168.1.66/xalionws/soap/Ixaliontest
  // ************************************************************************ //
  Ixaliontest = interface(IInvokable)
  ['{A3FB1A48-1AE7-B449-16DC-42CCE1A48832}']
    function  echoname(const Value: string): string; stdcall;
    function  sumall(const Value: Integer): Integer; stdcall;
  end;

function GetIxaliontest(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): Ixaliontest;


implementation
  uses System.SysUtils;

function GetIxaliontest(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): Ixaliontest;
const
  defWSDL = 'http://192.168.1.66/xalionws/wsdl/Ixaliontest';
  defURL  = 'http://192.168.1.66/xalionws/soap/Ixaliontest';
  defSvc  = 'Ixaliontestservice';
  defPrt  = 'IxaliontestPort';
var
  RIO: THTTPRIO;
begin
  Result := nil;
  if (Addr = '') then
  begin
    if UseWSDL then
      Addr := defWSDL
    else
      Addr := defURL;
  end;
  if HTTPRIO = nil then
    RIO := THTTPRIO.Create(nil)
  else
    RIO := HTTPRIO;
  try
    Result := (RIO as Ixaliontest);
    if UseWSDL then
    begin
      RIO.WSDLLocation := Addr;
      RIO.Service := defSvc;
      RIO.Port := defPrt;
    end else
      RIO.URL := Addr;
  finally
    if (Result = nil) and (HTTPRIO = nil) then
      RIO.Free;
  end;
end;


initialization
  { Ixaliontest }
  InvRegistry.RegisterInterface(TypeInfo(Ixaliontest), 'urn:xaliontestIntf-Ixaliontest', 'utf-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(Ixaliontest), 'urn:xaliontestIntf-Ixaliontest#%operationName%');

end.

在主窗体放两个按钮。

 

代码如下

implementation

{$R *.dfm}

uses Ixaliontest1;

procedure TForm2.Button1Click(Sender: TObject);
begin
  showmessage(  GetIxaliontest.echoname('xalion'));
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
  showmessage(  GetIxaliontest.sumall(100).tostring);
end;

编译运行。

 

 

 

可以看见,客户端很顺利的调用了服务器端的函数。

我们今天的任务完成了。

 

目录
相关文章
|
18天前
|
存储 Linux 开发工具
如何进行Linux内核开发【ChatGPT】
如何进行Linux内核开发【ChatGPT】
|
24天前
|
Java Linux API
Linux设备驱动开发详解2
Linux设备驱动开发详解
23 6
|
24天前
|
消息中间件 算法 Unix
Linux设备驱动开发详解1
Linux设备驱动开发详解
23 5
|
1月前
|
编解码 安全 Linux
基于arm64架构国产操作系统|Linux下的RTMP|RTSP低延时直播播放器开发探究
这段内容讲述了国产操作系统背景下,大牛直播SDK针对国产操作系统与Linux平台发布的RTMP/RTSP直播播放SDK。此SDK支持arm64架构,基于X协议输出视频,采用PulseAudio和Alsa Lib处理音频,具备实时静音、快照、缓冲时间设定等功能,并支持H.265编码格式。此外,提供了示例代码展示如何实现多实例播放器的创建与管理,包括窗口布局调整、事件监听、视频分辨率变化和实时快照回调等关键功能。这一技术实现有助于提高直播服务的稳定性和响应速度,适应国产操作系统在各行业中的应用需求。
|
2月前
|
Web App开发 缓存 Linux
FFmpeg开发笔记(三十六)Linux环境安装SRS实现视频直播推流
《FFmpeg开发实战》书中第10章提及轻量级流媒体服务器MediaMTX,适合测试RTSP/RTMP协议,但不适合生产环境。推荐使用SRS或ZLMediaKit,其中SRS是国产开源实时视频服务器,支持多种流媒体协议。本文简述在华为欧拉系统上编译安装SRS和FFmpeg的步骤,包括安装依赖、下载源码、配置、编译以及启动SRS服务。此外,还展示了如何通过FFmpeg进行RTMP推流,并使用VLC播放器测试拉流。更多FFmpeg开发内容可参考相关书籍。
74 2
FFmpeg开发笔记(三十六)Linux环境安装SRS实现视频直播推流
|
2月前
|
弹性计算 运维 自然语言处理
阿里云OS Copilot测评:重塑Linux运维与开发体验的智能革命
阿里云OS Copilot巧妙地将大语言模型的自然语言处理能力与操作系统团队的深厚经验相结合,支持自然语言问答、辅助命令执行等功能,为Linux用户带来了前所未有的智能运维与开发体验。
|
2月前
|
Ubuntu Linux Docker
Java演进问题之Alpine Linux创建更小的Docker镜像如何解决
Java演进问题之Alpine Linux创建更小的Docker镜像如何解决
|
Linux Windows Apache
使用delphi 10.2 开发linux 上的Daemon
delphi 10.2 支持linux, 而且官方只是支持命令行编程,目地就是做linux 服务器端的开发。 既然是做linux服务器端的开发,那么普通的命令行运行程序,然后等待开一个黑窗口的方式就 太low了(目前就有个别语言大咖,经常在Windows 上开个黑窗口,看起来非常恶心),那么如果 避免这个尴尬的问题?     其实Linux 下也有类似windows 服务的功能,Linux Daemon 就是其中的一种方式,命令行运行后 直接返回,同时在后台建立一个同样的进程。
1716 0
|
18天前
|
机器学习/深度学习 安全 网络协议
Linux防火墙iptables命令管理入门
本文介绍了关于Linux防火墙iptables命令管理入门的教程,涵盖了iptables的基本概念、语法格式、常用参数、基础查询操作以及链和规则管理等内容。
178 73
|
11天前
|
Linux Shell
Linux 中 Tail 命令的 9 个实用示例
Linux 中 Tail 命令的 9 个实用示例
40 6
Linux 中 Tail 命令的 9 个实用示例