databasedelphisoapfiredacsoapserver

WebModule in Delphi SOAP Application Server


Given that the each request message spawns a separate thread, and separate instances of the Web module and its contents are created dynamically for each thread, I added a FDConnection and FDQuery to the webmodule so that I can send a personnel profile from the database to the requester upon request. How can I access a web module instance?

In the web module there is only one variable of the web module metaclass :

var
  WebModuleClass: TComponentClass = TWebModule1;

for example:

WebModule.FDQuery.Close;

The CountryImpl unit is implementation of CountryIntf service

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.

Solution

  • Your assumption is incorrect: Only 1 instance of the webmodule is created in the SOAP server application. You should not add thread-specific functionality to the webmodule, you must add it to the CountryImp.pas. Since there is no design-surface there, you have to do runtime instantiation of FDConnection(s) and FDQueries in the functions in that unit.