Ricardo Pontual Ricardo Pontual - 1 month ago 4x
C# Question

Is it possible from WCF client to get the service IP behind a load balancer?

I know some ways to get the client IP from a WCF service, but I'm not able to get the server IP.

I can make some changes in the service, so it would be able to return the IP address, but I'm trying to do this without modify the service.

My scenario:
I call a service by a dns, that runs in a load balance (e.g. services.company.com, that resolves to, so I cannot know which server is responding the request ( or

enter image description here

For log purpose, I would like to know which server processed my request.

I think that probably it's not possible, but who knows can anyone help me or give a clue?


As I thought, I could not find any way to get the IP from a server without make changes in server side. But I've tried to hit the goal without modifying all services, and I ended up with this approach:


I added a custom header to my IIS Server, so when I consume a service, the server add a value to the header, that I can recover in client. Basically you can add a custom header in IIS Manager, or you can add to the configuration file, adding those lines to system.webServer node:

        <add name="X-ServerName" value="myServerNameOrIP" />

It can be done at server level or to some application in particular. This solved the issue.

Of course, I'm putting this only in internal servers, I don't want my external clients receiving this information.