简体   繁体   中英

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 (eg services.company.com, that resolves to 192.168.0.1), so I cannot know which server is responding the request (192.168.0.10 or 192.168.0.11).

在此输入图像描述

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:

https://www.iis.net/configreference/system.webserver/httpprotocol/customheaders

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:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM