How to get the IP address of a WCF web service

When calling the WCF web service from a C # client (System.ServiceModel.ClientBase <> instance), how can I get the IP address of the server I'm connected to?

Context: we set up a web farm for some WCF services, and I need to know which specific server I'm connected to when an exception occurs.

+3
source share
2 answers

You can add this to your catch:

    IPHostEntry heserver = Dns.GetHostEntry(Dns.GetHostName());
    IPAddress curAdd = heserver.AddressList[0];
    curAdd.ToString();
+4
source

Your load balancer is probably hiding a specific web server from you.

A common strategy is to log errors on the server and use some kind of log aggregator for operations to monitor all servers.

, , . , .

+1

All Articles