且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在WCF服务中获取客户端IP地址

更新时间:2022-06-21 22:13:42

查看此解决方案:在使用HTTPS 443绑定托管的WCF服务中获取客户端IP地址 [ ^ ]
Check out this solution: Get client IP address in a WCF Service hosted using HTTPS 443 bindings[^]


OperationContext oOperationContext = OperationContext.Current;
MessageProperties oMessageProperties = oOperationContext.IncomingMessageProperties;
RemoteEndpointMessageProperty oRemoteEndpointMessageProperty = (RemoteEndpointMessageProperty)oMessageProperties[RemoteEndpointMessageProperty.Name];

string szAddress = oRemoteEndpointMessageProperty.Address;
int nPort = oRemoteEndpointMessageProperty.Port;