# Getting a client ip address in HttpApi Service

**URL:** https://talk.remobjects.com/t/getting-a-client-ip-address-in-httpapi-service/25749
**Category:** Remoting SDK
**Tags:** net, delphi, httpapi
**Created:** [November 25, 2021, 3:11pm UTC](https://talk.remobjects.com/t/getting-a-client-ip-address-in-httpapi-service/25749 "2021-11-25T15:11:24Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![gscmsnhcokr](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/g/a5b964/32.png) [@gscmsnhcokr](https://talk.remobjects.com/u/gscmsnhcokr)
#### Post date: [November 25, 2021, 3:11pm UTC](https://talk.remobjects.com/t/getting-a-client-ip-address-in-httpapi-service/25749/1 "2021-11-25T15:11:24Z")

</div>

Hello.

I’m trying to convert some RODL services to HttpAPI.

In rodl service I could get client ip address like this

```auto
public virtual AOperation()
{
    ...
    var ip = (this.ServerChannel as IpHttpServerChannelInfo).RemoteEndPoint.Address;
    ...
}

```

but in HttpAPI service ServerChannel is always null.  
I tried implementing IChannelAwareService, but OnServiceActivated method never invoked.

How can I access ServerChannel of HttpAPI service and get client ip address.

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [November 25, 2021, 5:27pm UTC](https://talk.remobjects.com/t/getting-a-client-ip-address-in-httpapi-service/25749/3 "2021-11-25T17:27:26Z")

</div>

Logged as [bugs://D19186](https://www.remobjects.com/portal/bugs/?id=D19186).

---

<div class="post-metadata">

### Author: ![antonk](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/a/a5b964/32.png) [@antonk](https://talk.remobjects.com/u/antonk)
#### Post date: [November 25, 2021, 5:28pm UTC](https://talk.remobjects.com/t/getting-a-client-ip-address-in-httpapi-service/25749/4 "2021-11-25T17:28:38Z")

</div>

Hello

Unfortunately it is not possible to retrieve this information in the current implementation of HttpAPI  
I have logged an issue to investigate if it is possible to provide this information.

Sorry for the inconvenience

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [November 29, 2021, 4:58pm UTC](https://talk.remobjects.com/t/getting-a-client-ip-address-in-httpapi-service/25749/5 "2021-11-29T16:58:17Z")

</div>

[bugs://D19186](https://www.remobjects.com/portal/bugs/?id=D19186) was closed as fixed.

---

<div class="post-metadata">

### Author: ![jptechon](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@jptechon](https://talk.remobjects.com/u/jptechon)
#### Post date: [December 6, 2021, 5:16am UTC](https://talk.remobjects.com/t/getting-a-client-ip-address-in-httpapi-service/25749/6 "2021-12-06T05:16:11Z")

</div>

As I using delphi, is it fixed also?

How can I get the update if fixed? I need update to which version?

joe

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [December 6, 2021, 10:05am UTC](https://talk.remobjects.com/t/getting-a-client-ip-address-in-httpapi-service/25749/7 "2021-12-06T10:05:50Z")

</div>

Hi,

> [@jptechon](#):
>
> As I using delphi, is it fixed also?

in Delphi you can use the `OnGetDispatchInfo` event.  
see more info at the [Receiving information about client on server-side](https://talk.remobjects.com/t/receiving-information-about-client-on-server-side/10981) topic

---

<div class="post-metadata">

### Author: ![jptechon](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@jptechon](https://talk.remobjects.com/u/jptechon)
#### Post date: [December 7, 2021, 10:05am UTC](https://talk.remobjects.com/t/getting-a-client-ip-address-in-httpapi-service/25749/8 "2021-12-07T10:05:05Z")

</div>

As my Project function call is HttpApi, How can I get the client wan ip within the httpapi call ?

joe

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [December 7, 2021, 10:06am UTC](https://talk.remobjects.com/t/getting-a-client-ip-address-in-httpapi-service/25749/9 "2021-12-07T10:06:44Z")

</div>

Hi,

You can store it in local variable of service or inside the Session

---

<div class="post-metadata">

### Author: ![jptechon](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@jptechon](https://talk.remobjects.com/u/jptechon)
#### Post date: [December 7, 2021, 10:10am UTC](https://talk.remobjects.com/t/getting-a-client-ip-address-in-httpapi-service/25749/10 "2021-12-07T10:10:02Z")

</div>

as some httpapi function call no session is needed, can you explain how to store it in a local variable ?

as my understanding , the httpapi ia independent of each call if no session is needed.

joe

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [December 7, 2021, 10:23am UTC](https://talk.remobjects.com/t/getting-a-client-ip-address-in-httpapi-service/25749/11 "2021-12-07T10:23:59Z")

</div>

Hi,

you can store info about **current** call in private variable of service.

for example, this code:

```auto
  [ROService( __ServiceName,__ ServiceID)]
  [RONamespace(fServerDataModule.__RODLLibraryNamespace)]
  [ROStandardClassFactory]
  TNewProjectService = class(TRORemoteDataModule)
    procedure RORemoteDataModuleGetDispatchInfo(const aTransport: IROTransport; const aMessage: IROMessage);
  private
    faddress: string;
  public
    [ROServiceMethod]
    [ROCustom('HttpApiPath', 'test')]
    [ROCustom('HttpApiMethod', 'Get')]
    function NewMethod: string;
  end;

implementation

{%CLASSGROUP 'System.Classes.TPersistent'}
{$R *.dfm}

function TNewProjectService.NewMethod: string;
begin
  Result := faddress;
end;

procedure TNewProjectService.RORemoteDataModuleGetDispatchInfo(const aTransport: IROTransport; const aMessage: IROMessage);
begin
  faddress := (aTransport as IROHTTPTransport).ClientAddress;
end;

```

will return client address:

```auto
Y:\>curl -v -X GET "http://localhost:8099/api/test" -H "accept: application/json" -H "Authorization: Basic YTpi"
Note: Unnecessary use of -X or --request, GET is already inferred.
* Trying ::1...
* TCP_NODELAY set
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8099 (#0)
> GET /api/test HTTP/1.1
> Host: localhost:8099
> User-Agent: curl/7.56.0
> accept: application/json
> Authorization: Basic YTpi
>
< HTTP/1.1 200 OK
< Connection: close
< Content-Type: application/json; charset=utf-8
< Content-Length: 11
< Date: Tue, 07 Dec 2021 10:21:28 GMT
< WWW-Authenticate: Basic realm="aaaa"
< Accept-Encoding: gzip, identity
<
"127.0.0.1"
* Closing connection 0

```
