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

 1 //WebService
 2 
 3 string clientIP = HttpContext.Current.Request.UserHostAddress;
 4 
 5 
 6 //WCF
 7 
 8            //提供方法执行的上下文环境
 9             OperationContext context = OperationContext.Current;
10             string toa = context.IncomingMessageHeaders.Action;
11             Uri to = context.IncomingMessageHeaders.To;
12             //获取传进的消息属性
13             MessageProperties properties = context.IncomingMessageProperties;
14             //获取消息发送的远程终结点IP和端口
15             RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
16 
17        string msg = String.Format("IP[{0}]Port[{1}]Url[{2}]Action[{3}]访问受限", endpoint.Address, endpoint.Port, to.AbsoluteUri, toa);
18                 Logger.WriteInfo(msg, "", logPath, GlobalContext.Logs);

 

posted @ 2016-01-28 20:31  J.Y  阅读(508)  评论(0编辑  收藏  举报