如何获取一个WCF远程端点的IP地址?地址、WCF、IP

2023-09-03 01:20:05 作者:思念成悲成泪

有没有办法让一个WCF连接的远程IP地址?

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

我想,为什么它没有内置到WCF框架的原因是WCF可以与非TCP / IP绑定工作,因此IP地址并不总是有意义的。

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.

然而,信息才有意义为所有广泛使用的绑定(据我所知:BasicHttp,DualHttp,WSHttp和NetTcp)。

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

的IP地址可能是访问使用反射,但我宁愿找一个记录的方式来获得它,而不是黑客进入的框架类。

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

我GOOGLE了在这个问题上,似乎很多人都碰到它没有找到一个体面的解决办法(通常的答案是to依靠邮件头的,但是这意味着信任的客户提供其真实IP地址,这是不是一种选择,如果你想登录出于安全原因,IP地址)

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)

推荐答案

显然,它已经在3.5通过RemoteEndpointMessageProperty;看到这里。

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