WCF 中的 IPv4 远程地址 [英] IPv4 remote address in WCF

查看:17
本文介绍了WCF 中的 IPv4 远程地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关如何获取IPWCF 远程端点的地址?

我正在使用此代码在调用工作流方法时检索远程 IP 地址:

I am using this code to retrieve the remote IP address when a workflow method is invoked:

private static string GetRemoteIP()
{
  var oc = OperationContext.Current;
  var mp = oc.IncomingMessageProperties;
  var remp = mp[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

  return remp == null ? "(unknown)" : remp.Address;
}

然而,我得到的地址是::1".我不想要 IPv6 地址,我想要 IPv4 地址 (127.0.0.1) - 有什么强制方法吗?

However, the address I get back is "::1". I don't want the IPv6 address, I want the IPv4 one (127.0.0.1) - any way of forcing this?

推荐答案

不,我不这么认为.您基本上只是在调用时读出客户端设置的属性.您唯一的选择是指示客户端(通过某些配置)始终使用 IPv4 而不是 IPv6(即一起关闭 IPv6).

No, I don't think so. You basically just read out a property set by the client at the time of the call. Your only option would be to instruct the client (through some config) to use IPv4 instead of IPv6 at all times (i.e. turn off IPv6 all together).

我不知道有任何 WCF 设置可以强制执行此操作 - 您必须深入研究网络堆栈,看看是否有任何方法可以使其使用 IPv4 地址而不是 IPv6.

I'm not aware of any WCF setting to enforce that - you'd have to dig into the network stack and see if there's any way to make it use IPv4 addresses instead of IPv6.

这篇关于WCF 中的 IPv4 远程地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆