WCF 获取客户端IP

简介: public class Service2 : IService2 { public User DoWork() { Console.
  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;
        }
    }

 

目录
相关文章
|
6月前
|
Windows
WCF服务端调用客户端.
WCF服务端调用客户端.