1

I'm using the latest WCF version. I'm getting the client's IP address like that:

        OperationContext context = OperationContext.Current;
        MessageProperties prop = context.IncomingMessageProperties;
        RemoteEndpointMessageProperty endpoint = prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
        string ip = endpoint.Address;

The IP I get is:

::1

What does it mean, can someone explain me this format?

Is it because of the binding? I use basicHttpBinding

chris
  • 111
  • 1
  • 8

1 Answers1

2

That is the IPv6 loopback address

https://en.wikipedia.org/wiki/Localhost

i.e. The client is on the same machine and is connecting to the service using IPv6

Scott Perham
  • 2,410
  • 1
  • 10
  • 20
  • Thanks, that makes sense. Is it possible to get client's IPv4 ? – chris Sep 09 '16 at 14:17
  • As it happens, this is very close to http://stackoverflow.com/questions/2028879/ipv4-remote-address-in-wcf which has some suggestions – Scott Perham Sep 09 '16 at 14:18
  • I saw that. The answer is from 2010 though, and it basically says _"I'm not aware of any WCF setting to enforce that - you'd have to dig into the network stack and see if there's any way to make it use IPv4 addresses instead of IPv6."_ So I was wondering if there is a way to normalize a client's IP address (so I will log IP in just one format) – chris Sep 09 '16 at 14:22
  • It's basically about which network protocols you support. In a _not so very helpful_ way, I don't know how you would disable IPv6 in the service as it's actually handled at a much lower level in the OS. You could maybe attempt to lookup the IPv4 address?... I've just found this: https://msdn.microsoft.com/en-us/library/system.net.ipaddress.maptoipv4%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396 – Scott Perham Sep 09 '16 at 14:29
  • Thanks, I will look into it – chris Sep 09 '16 at 14:50