如何获取调用WCF服务的IP地址 [英] How to get IP Address of Calling WCF service
本文介绍了如何获取调用WCF服务的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最近我有一个新的要求,我有多个WCF服务调用,他们正在调用并请求彼此响应,现在我想检索在另一个WCF服务中调用WCF服务的IP地址。
请帮助我,我将不胜感激。
Recently I am having a new requirement, in which I have multiple WCF service call, they are calling and requesting response for each other, Now I wanted to retrieve IP address of calling WCF service in another WCF service.
Please help me, I would be grate appreciated.
推荐答案
如果您的WCF托管在Web服务器环境中,可以执行以下操作:
在您的配置文件中:
If your WCF's are hosted in a web server environment you can do the following:
In your config file:
<system.servicemodel>
!-- this enables WCF services to access ASP.Net http context -->
<servicehostingenvironment aspnetcompatibilityenabled="true" />
</system.servicemodel>
您应该可以使用以下方式访问客户端IP:
You should then be able to access the client IP using:
HttpContext.Current.Request.UserHostAddress
这篇关于如何获取调用WCF服务的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文