在使用HTTPS 443绑定托管的WCF服务中获取客户端IP地址

and*_*ndy 14 c# https wcf ip-address

在我的一个需要的应用程序中,使用HTTPS 443绑定托管的WCF服务中的客户端IP地址.

我尝试了堆栈溢出和其他网站关于这个问题的大部分帖子但是当我在服务器中托管我的应用程序时它只是获取服务器IP地址但我需要客户端地址任何有任何想法

提前致谢..

小智 29

在.NET 3.5中,您可以使用以下模式(使用System.ServiceModel)

OperationContext context = OperationContext.Current; 
MessageProperties prop = context.IncomingMessageProperties; 
RemoteEndpointMessageProperty endpoint = prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
string ip = endpoint.Address; 
Run Code Online (Sandbox Code Playgroud)