What a pain! but this works. Add references to:
using System.ServiceModel.Channels;
using System.Net;
.....
Then this will get the client's IP address from the incoming message header on your IIS hosted WCF Web Service and resolve to the host:
string ComputerName = "NOTFOUND";
try
{
var remp = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
string[] computer_name = Dns.GetHostEntry(remp.Address).HostName.Split(new Char[] { '.' });
ComputerName = computer_name[0].ToString();
}
catch (Exception e)
{
ComputerName = "NOTFOUND";
}
Nice example. I used it. You do not need the ToString() here:
ReplyDeleteComputerName = computer_name[0].ToString();