简体   繁体   English

WCF operationContext返回网关而不是客户端IP地址

[英]WCF operationContext returns gateway instead of client ip address

im kinda new to developing WCF services. 对开发WCF服务来说有点新。 I'm using this code to get the client ip address, 我正在使用此代码来获取客户端IP地址,

private String getRemoteIP()
{
    OperationContext context = OperationContext.Current;
    MessageProperties prop = context.IncomingMessageProperties;
    RemoteEndpointMessageProperty endpoint = prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
    return endpoint.Address;
}

in my localhost it works fine, but when i install my service in a server for testing, what I get in return is the client's gateway, any insight on the reason why that could be ??? 在我的本地主机中,它工作正常,但是当我在服务器上安装我的服务进行测试时,得到的回报是客户端的网关,对此原因的任何见解都可以?

try this one instead: First of all enable AspNetCompatibility mode, as follows: 请尝试以下一种方法:首先启用AspNetCompatibility模式,如下所示:

<system.serviceModel>
        <!-- this enables WCF services to access ASP.Net http context -->
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>

And then you can get the IP address by: 然后您可以通过以下方式获取IP地址:

HttpContext.Current.Request.UserHostAddress

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

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