web-servicesdelphidelphi-xeremobjects

Get clients ip address in a RemObjects webservice


I have a webservice implemented using RemObjects over Delphi XE and I want to know the ip address of the clients petitions. My service inherits from TRORemoteDataModule and I haven't found any method or object to do that.

Any suggestion? Thanks

Note: I think that the information that I need is returning in the method self.transport.GetTransportObject() but it returns a TObject and I don't know how to extract this information


Solution

  • This is how I get it from a SuperChannel:

    procedure TMyInterface.RORemoteDataModuleGetDispatchInfo(const aTransport: IROTransport; const aMessage: IROMessage);
    var
      tcpinfo: IROTCPTransport; 
      Session: TCustomSession;
      szClientIP : String;
    begin
      Session := TCustomSession(Self.Session);
      if Supports(aTransport, IROTCPTransport, tcpinfo) then
      begin
        szClientIP := tcpinfo.ClientAddress;
        if (not Session.ShownTCP) or (Session.TCPAddress <> szClientIP) then
        begin
          Session.TCPAddress := szClientIP;
          Session.Report(leInformation, 'TCP address ' + szClientIP); 
          Session.ShownTCP := True; 
        end; 
      end 
      else 
      begin 
        Session.Report(leInformation, 'TCP address not available');
      end;
    end;
    

    The specifics of what you do with it are up to you, but you have to get it as it is set up, and store it in the session object if you want to pick it up later. I implemented a custom session to hold the client Ip so that I could get it any time in further calls.