tags:

views:

1156

answers:

3

I have a WCF service that is hosted via IIS on multiple web servers. I have a logging method that logs the calls to the database and I'd like to log which server the call is executing on.

Does anyone know how to get the Host server name or ip address that the WCF call is executing on?

+1  A: 

Dns.GetHostName() is what i use the most.

Darren Kopp
+1  A: 

Use Dns.GetHostName(), because it's much better to get the name of the computer than the host IP. Consider the case when your host computer have more than one IP address, has virtual network cards (VMWare).

Thomasek
A: 

This is what worked for us. Make sure you have a reference to System.ServiceModel. Then implement the following code in your service method:

var context = System.ServiceModel.OperationContext.Current;

RemoteEndpointMessageProperty property = (RemoteEndpointMessageProperty)context.IncomingMessageProperties[RemoteEndpointMessageProperty.Name];

string externalIP = property.Address;
Dion