How to get IP address of WCF web service
When calling a WCF web service from a C# client (instance of System.ServiceModel.ClientBase<>) how can I get the IP address of the s开发者_如何学编程erver I'm connected to?
Context: we've setup a web farm for some WCF services and I need to know which specific server I'm connected to when an exception occurs.
You can add this to your catch:
IPHostEntry heserver = Dns.GetHostEntry(Dns.GetHostName());
IPAddress curAdd = heserver.AddressList[0];
curAdd.ToString();
Your load balancer presumably is hiding the specific web server from you.
The usual strategy is to log errors per-server and use a log aggregator of some sort for operations to monitor all servers.
If your client code really needs to know the specific server, consider returning that information as part of the exception. After all, the server knows it's own identity.
精彩评论