Delphi SOAP 应用服务器中的 WebModule

问题描述

鉴于每个请求消息产生一个单独的线程,并且为每个线程动态创建 Web 模块的单独实例及其内容,我向 Web 模块添加了 FDConnection 和 FDQuery,以便我可以从根据请求将数据库发送给请求者。 如何访问网络模块实例?

Web 模块中只有一个 Web 模块元类变量

var
  WebModuleClass: TComponentClass = TWebModule1;

例如:

WebModule.FDQuery.Close;

CountryImpl 单元是 CountryIntf 服务的实现

unit CountryImpl;

interface

uses Soap.InvokeRegistry,System.Types,Soap.XSBuiltIns,uCountry,CountryIntf,WebModuleUnit1;

type

  TCountryManager = class(TInvokableClass,ICountryManager)
  public
    function GetCountry(ACountryId: integer): TCountry;
  end;

implementation


{ TCountry }

function TCountryManager.GetCountry(ACountryId: integer): TCountry;
begin
  WebModule.FDQuery.Close;
  WebModule.FDQuery.ParamByName('Id').Value := ACountryId;
  WebModule.FDQuery.Open;
end;

initialization
   InvRegistry.RegisterInvokableClass(TCountryManager);
end.

解决方法

您的假设不正确:在 SOAP 服务器应用程序中仅创建了 1 个 webmodule 实例。您不应将特定于线程的功能添加到 web 模块,您必须将其添加到 CountryImp.pas。由于那里没有设计图面,您必须在该单元的函数中对 FDConnection(s) 和 FDQueries 进行运行时实例化。