WebService及WCF获取客户端IP,端口

时间:2023-03-09 03:02:40
WebService及WCF获取客户端IP,端口

wcf获取客户端IP,端口

var context = OperationContext.Current;
var properties = context.IncomingMessageProperties; //获取传进的消息属性
var endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; //获取消息发送的远程终结点IP和端口
string UserLoginIp = endpoint.Address; // 获取发送消息的客户端的 IP 地址。
string UserLoginProt = endpoint.Port.ToString(); //获取发送消息的客户端的端口号。

webservice获取客户端IP

string clientIP = HttpContext.Current.Request.UserHostAddress;

写于 2014-04-10