在WCF服务获取客户端的IP地址使用HTTPS托管443个绑定(Get client IP addr

2019-06-25 12:44发布

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

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

提前致谢..

Answer 1:

在.NET 3.5,你可以做使用下面的模式(使用System.ServiceModel

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


文章来源: Get client IP address in a WCF Service hosted using HTTPS 443 bindings