![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 public partial class ShareService : IUserServers
2 {
3 public int InsertUserInfo(Model.UserServersModel.UserServers userServers)
4 {
5 var context = OperationContext.Current;
6
7 var properties = context.IncomingMessageProperties; //获取传进的消息属性
8
9 var endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; //获取消息发送的远程终结点IP和端口
10
11 userServers.UserLoginIp = endpoint.Address; // 获取发送消息的客户端的 IP 地址。
12 userServers.UserLoginProt = endpoint.Port.ToString(); //获取发送消息的客户端的端口号。
13
14 userServers.UserLoginTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //服务器时间
15 return BLL.UserServersManage.UserServers.InsertUserInfo(userServers);
16 }
17 }
2 {
3 public int InsertUserInfo(Model.UserServersModel.UserServers userServers)
4 {
5 var context = OperationContext.Current;
6
7 var properties = context.IncomingMessageProperties; //获取传进的消息属性
8
9 var endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; //获取消息发送的远程终结点IP和端口
10
11 userServers.UserLoginIp = endpoint.Address; // 获取发送消息的客户端的 IP 地址。
12 userServers.UserLoginProt = endpoint.Port.ToString(); //获取发送消息的客户端的端口号。
13
14 userServers.UserLoginTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //服务器时间
15 return BLL.UserServersManage.UserServers.InsertUserInfo(userServers);
16 }
17 }