原文:http://blog.163.com/felex_cheng@126/blog/static/4104700520124301023042/

wcf:
            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:

            string clientIP = HttpContext.Current.Request.UserHostAddress;