Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing the original TWebRequest object in a Delphi SOAP Server

Summary: How do you access the original TWebRequest object in a Delphi Soap Server Application ?

My web service publishes a service ITest with a method CallMe:

ITest = interface(IInvokable)
['{AA226176-FFAD-488F-8768-99E706450F31}']
  function CallMe: string; stdcall;
end;
...
initialization
InvRegistry.RegisterInterface(TypeInfo(ITest));

This interface is implemented in a class:

TTest = class(TInvokableClass, ITest)
public
  function CallMe: string; stdcall;
end;
...
initialization
InvRegistry.RegisterInvokableClass(TTest, TestFactory);

How do I access the original TWebRequest object inside of the implementation of this method ? E.g. If I want to check what cookies were set, or read other properties on the request:

function TTest.CallMe: string;
begin
  // how to access TWebRequest object
  ...
end;
like image 785
David Moorhouse Avatar asked May 01 '12 22:05

David Moorhouse


1 Answers

uses
  System.SysUtils,
  Web.HTTPApp,
  Soap.WebBrokerSOAP;

function TTest.CallMe: string;
var
  WebDispatcher: IWebDispatcherAccess;
begin
  Result := '';
  if Supports(GetSOAPWebModule, IWebDispatcherAccess, WebDispatcher) then
    Result := Format('You are calling me from: %s', [WebDispatcher.Request.RemoteIP]);
end;
like image 180
Ondrej Kelle Avatar answered Nov 02 '22 21:11

Ondrej Kelle