[英]How do I get a client's address from a WCF Service Application?
How can I get a client's address from a WCF Service Application? 如何从WCF服务应用程序获取客户端的地址? Also, is there an event raised when a client connects, possibly with address information? 此外,当客户端连接时是否会引发事件,可能还有地址信息?
In 3.0, this is quite hard; 在3.0中,这很难; but was improved in 3.5 ( read Detect Client IP in WCF 3.5 ). 但在3.5中有所改进( 在WCF 3.5中读取检测客户端IP )。 I'm not aware of an event, though. 不过,我不知道有什么事。
Which address are you looking for? 你在找哪个地址? The IP address? IP地址?
If so, I hope you're aware of the limitations on that - it won't be accurate if the client's on the other side of a NAT device or Internet proxy. 如果是这样,我希望您了解其中的限制 - 如果客户端位于NAT设备或Internet代理的另一端,则不准确。
If System.Web.HttpContext.Current.Request.UserHostAddress isn't null, then it has the remote address. 如果System.Web.HttpContext.Current.Request.UserHostAddress不为null,则它具有远程地址。 But that might be a proxy or load balancer (the case I have in our production environment). 但这可能是代理或负载均衡器(我在生产环境中的情况)。
如果WCF主机提供获取服务请求者IP的方法会更容易 - 这样您就可以调用该方法来获取原始请求者。
您可以使用类似于OperationContext.Current.IncomingMessageHeaders.To.Host
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.