本文介绍了在 WCF 3.0 中获取客户端 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
显然,您可以在 WCF 3.5 中轻松获取客户端 IP 地址,但在 WCF 3.0 中则不然.有人知道怎么做吗?
Apparently you can easily obtain a client IP address in WCF 3.5 but not in WCF 3.0. Anyone know how?
推荐答案
事实证明您可以,只要 (a) 您的服务托管在 Web 服务中(显然)并且 (b) 您启用 AspNetCompatibility 模式,如下:
It turns out you can, so long as (a) your service is being hosted in a Web Service (obviously) and (b) you enable AspNetCompatibility mode, as follows:
<system.serviceModel>
<!-- this enables WCF services to access ASP.Net http context -->
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
...
</system.serviceModel>
然后您可以通过以下方式获取 IP 地址:
And then you can get the IP address by:
HttpContext.Current.Request.UserHostAddress
这篇关于在 WCF 3.0 中获取客户端 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!