Search code examples
web-servicesdelphicgiglobal-variablesdelphi-7

Delphi 7 CGI web service global parameter


I need to set a global parameter in the Webmodule of my Delphi CGI webservice so that I can use it throughout the life of the request as a unique identifier (traceId) for logging purposes. The unique identifier needs to be generated in the Webmodule because the first thing I log is the raw XML that is received. I then log all sorts of debug information in my actual web service methods and I needs the Id to tie these all together.

I can't figure out a way to do this. The actual Webmodule is not accessible in my webservice methods and any attempts just throw an access violation. I'm probably doing this in completely the wrong way but I can think of another solution.

Any ideas?


Solution

  • Assuming you're talking about a SOAP webservice, you can use GetSOAPWebModule to get a reference to your web module from within your service method.

    Example:

    uses
      WebBrokerSOAP, MyWebModuleUnit;
    
    procedure TMyService.MyMethod;
    var
      MyWebModule: TMyWebModule;
      TraceID: Integer;
    begin
      MyWebModule := GetSOAPWebModule as TMyWebModule;
      TraceID := MyWebModule.TraceID;
    end;