.net – How to get the IP address of a WCF remote endpoint

netwcfwcf-binding

Is there a way to get the remote IP Address of a WCF connection?

I guess the reason why it's not built-in into the WCF framework is that WCF can work with non TCP/IP bindings, so the IP Address is not always meaningful.

However, the information would make sense for all the widely used bindings (As far as I know : BasicHttp, DualHttp, WSHttp and NetTcp).

The IP address is probably accessible using reflection, but I'd rather find a documented way to get it rather than hacking into the framework classes.

I've googled on the issue, and it seems a lot of people have run into it without finding a decent solution (The usual answer is to rely on the message headers, but this implies trusting the client to provide its real IP Address, which is not an option if you want to log the IP Address for security reasons)

Best Answer

Apparently it has been added in 3.5 via RemoteEndpointMessageProperty; see here.