繁体   English   中英

如何在Linux的WCF服务中获取客户端IP?

[英]How to get client IP in WCF service in Linux?

我有一个WCF服务,它在Debian中的Mono下工作。
我的目标是获取服务中的客户端IP地址。
我已经阅读了大量类似的主题,这些主题表明主要的解决方案是使用RemoteEndpointMessageProperty

OperationContext oOperationContext = OperationContext.Current;
MessageProperties oMessageProperties = oOperationContext.IncomingMessageProperties;

var prop = oMessageProperties[RemoteEndpointMessageProperty.Name];
RemoteEndpointMessageProperty oRemoteEndpointMessageProperty = prop as RemoteEndpointMessageProperty;

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

我所做的与上图相同。
但是问题在于oMessageProperties不包含键RemoteEndpointMessageProperty.Name ,它只有带有值System.ServiceModel.Channels.BinaryMessageEncoder “ Encoder”。

任何人都知道为什么会发生这种情况以及如何解决此问题?

我在Mono 3.2.8下使用NetTcpBinding

请尝试以下操作:

var iPAddress = HttpContext.Current.Request.UserHostAddress;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM