WCF 获取客户端IP

  public class Service2 : IService2
    {
        public User  DoWork()
        {
            Console.WriteLine(ClientIpAndPort());
            return new User { Name = "sdf", Age = 12 };
        }
        public string ClientIpAndPort()
        {
            OperationContext context = OperationContext.Current;
            MessageProperties properties = context.IncomingMessageProperties;
            RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

            return endpoint.Address+"port"+endpoint.Port;
        }
    }

 

posted @ 2013-07-25 17:51  幕三少  阅读(623)  评论(0编辑  收藏  举报