• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

delphiwebservice服务端开发

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

delphi webservice服务端开发

1)引用单元

ueses
  Web.WebReq,
  IdHTTPWebBrokerBridge;

2)WebModuleUnit1单元,DELPHI WEBSERVICE向导自动生成的

if Web.WebReq.WebRequestHandler <> nil then
    Web.WebReq.WebRequestHandler.WebModuleClass := WebModuleUnit1.WebModuleClass;

3)创建indy通讯

var FServer: TIdHTTPWebBrokerBridge;
FServer := TIdHTTPWebBrokerBridge.Create(Self);
FServer.DefaultPort := port;
FServer.Bindings.Clear;
FServer.Active := True;

4)接口声明单元,DELPHI WEBSERVICE向导自动生成的。

unit WebservicesIntf;

interface

uses Soap.InvokeRegistry, System.Types;

type
  TGoods = class(TRemotable)
  private
    FGoodsId: String;
    FGoodsName: String;
  published
    property GoodId: String read FGoodsId write FGoodsId;
    property GoodName: String read FGoodsName write FGoodsName;
  end;

  TGoodsArray = array of TGoods;

  TClass1 = class(TRemotable)
  private
    FId: String;
    FName: UnicodeString;
  published
    property Id: String read FId write FId;
    property Name: String read FName write FName;
  end;

  TClass1Array = array of TClass1;

  { Invokable interfaces must derive from IInvokable }
  IynServices = interface(IInvokable)
  ['{91ACA512-4204-4FAF-A26D-05E265BEAA72}']

    { Methods of Invokable interface must not use the default }
    { calling convention; stdcall is recommended }
    function getClass1Array: TClass1Array; stdcall;
    function saveClass1Array(value: TClass1Array): Boolean; stdcall;
    function GetGoodsArray(AAccountNo, ASQL: string): TGoodsArray; stdcall;
    function GetGoods(AAccountNo, ASQL: string): string; stdcall;
  end;

implementation

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

end.

  5)接口实现单元,DELPHI WEBSERVICE向导自动生成的

{ Invokable implementation File for TTest which implements ITest }

unit WebservicesImpl;

interface

uses
  ynJsonSerial, System.SysUtils, uUnidacPool, uUnidac, uLog, Soap.InvokeRegistry,
  System.Types, WebservicesIntf;

type

  { TynServices }
  TynServices = class(TInvokableClass, IynServices)
  public
    function getClass1Array: TClass1Array; stdcall;
    function saveClass1Array(value: TClass1Array): Boolean; stdcall;
    function GetGoodsArray(AAccountNo, ASQL: string): TGoodsArray; stdcall;
    function GetGoods(AAccountNo, ASQL: string): string; stdcall;
  end;

implementation

{ TynServices }

function TynServices.getClass1Array: TClass1Array;
begin
  SetLength(Result, 2);
  Result[0] := TClass1.Create;
  Result[0].Id := '编号1';
  Result[0].Name := '名称1';
  Result[1] := TClass1.Create;
  Result[1].Id := '编号2';
  Result[1].Name := '名称2';
end;

function TynServices.GetGoods(AAccountNo, ASQL: string): string;
begin
  var pool: TUnidacPool := GetDBPool(AAccountNo);
  var js: TynJsonCross := TynJsonCross.Create;
  var dm: TUnidac := pool.Lock;
  try
    try
      dm.qry.Close;
      dm.qry.SQL.Clear;
      dm.qry.SQL.Add(ASQL);
      dm.qry.Open;
      Result := js.DataSetToJson(dm.qry);
    except
      on E: Exception do
        Log.WriteLog('TynServices.GetGoods ' + E.Message);
    end;
  finally
    js.Free;
    pool.Unlock(dm);
  end;
end;

function TynServices.GetGoodsArray(AAccountNo, ASQL: string): TGoodsArray;
//var
//  dbpool: TDBPool;
//  firedac: TynFiredac;
begin
//  dbpool := GetDBPool(AAccountNo);
//  firedac := dbpool.Lock;
//  try
//    try
//      firedac.FDQuery1.Close;
//      firedac.FDQuery1.SQL.Clear;
//      firedac.FDQuery1.SQL.Add(ASQL);
//      firedac.FDQuery1.Open;
//      SetLength(Result, firedac.FDQuery1.RecordCount);
//      firedac.FDQuery1.First;
//      while not firedac.FDQuery1.Eof do
//      begin
//        Result[firedac.FDQuery1.RecNo].GoodId := firedac.FDQuery1.FieldByName('goodsid').AsString;
//        Result[firedac.FDQuery1.RecNo].GoodName := firedac.FDQuery1.FieldByName('goodsname').AsString;
//        firedac.FDQuery1.Next;
//      end;
//    except
//      on E: Exception do
//      begin
//        Log.WriteLog('TynServices.GetGoodsArray ' + E.Message);
//      end;
//    end;
//  finally
//    firedac.FDQuery1.Close;
//    firedac.FDConnection1.Close;
//    dbpool.Unlock(firedac);
//  end;
end;

function TynServices.saveClass1Array(value: TClass1Array): Boolean;
begin
  Result := False;
end;

initialization
{ Invokable classes must be registered }
  InvRegistry.RegisterInvokableClass(TynServices);

end.

  

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Matlab 双目标定工具箱发布时间:2022-07-18
下一篇:
MATLAB——线性神经网络发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap