WCF服务端怎么取得正在会话的远程客户端地址、端口Trace.WriteLine(OperationContext.Current.Channel.RemoteAddress.ToString());
输出:http://schemas.microsoft.com/2005/12/ServiceModel/Addressing/Anonymous有大虾知道吗?
输出:http://schemas.microsoft.com/2005/12/ServiceModel/Addressing/Anonymous有大虾知道吗?
这个也没有用
"我也不知道,如果我做的话,我会让客户端登录时向服务器"报告"自己的IP和端口."
这个不现实, 你的客户端的连接请求经过NAT以后, 在服务器端看到的并不是你的客户端的真正IP,
比如, 你的客户端在局域网内, IP:192.168.1.13, 连接到服务器后, 服务器拿着那个地址一点用都没有,
所以你的报告显得毫无意义;
public string GetClientIP()
{
OperationContext context = OperationContext.Current;
MessageProperties messageProperties = context.IncomingMessageProperties;
RemoteEndpointMessageProperty endpointProperty =
messageProperties [RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
string ipAddress = endpointProperty.Address;
return ipAddress;
}可以看下: http://blogs.msdn.com/phenning/archive/2007/08/08/remoteendpointmessageproperty-in-wcf-net-3-5.aspx