8

I'm currently looking at the OperationContect.Current properties. Is there a (nested) property the will always return the machine name of the client? I'm currently using net.tcp binding, but would like to support additional bindings in the future.

Using .NET 3.5 SP1

chilltemp
  • 8,854
  • 8
  • 41
  • 46
  • Unless you send the caller's machine name as a WCF header, you won't be able to retrieve it – marc_s Feb 17 '11 at 21:17
  • With machine name you mean the fully qualified domain as registered in the domain name server for the ip-address? – rene Feb 17 '11 at 21:19
  • Preferably the fully qualified domain name, but what is classically known as the netbios name will suffice for my needs. – chilltemp Feb 17 '11 at 21:22
  • To clarify, this is all within the same domain. I am not expecting this to be used in a public service. – chilltemp Feb 17 '11 at 21:25

1 Answers1

8

You can get the remote endpoint's IP address from the current OperationContext's IncomingMessageProperties, eg:

RemoteEndpointMessageProperty messageProperty = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
Console.WriteLine("Remote address is: {0}", messageProperty.Address);
Chris Wenham
  • 23,679
  • 13
  • 59
  • 69
  • +1 technically that is not the name but this was also my first guess. Could add a dns lookup.... – rene Feb 17 '11 at 21:18
  • 1
    Yeah, I don't think WCF encodes the full hostname in requests (it's not necessary to function, and would just add overhead). A reverse DNS lookup may work as long as there's no NAT between them. – Chris Wenham Feb 17 '11 at 21:20
  • 1
    I am getting server name where I am hosting my service like localhost:5555 – Ziggler Nov 16 '19 at 00:13