代码之家  ›  专栏  ›  技术社区  ›  CaffGeek

我能得到wcf呼叫者的网址吗…?

  •  1
  • CaffGeek  · 技术社区  · 14 年前

    我有一个从不同地方调用的WCF服务

    我有一个方法来获取调用者的IP和主机名。

    但我希望能够得到完整的网址,如果是另一个服务,ASPX网页等,正在作出的呼叫呼叫者。

    有可能吗?

    目前我所拥有的基本上是:

    public static string GetHostName()
    {
        var hostName = "UNKOWN";
    
        try
        {
            var remoteEndpointMessageProperty = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
            hostName = remoteEndpointMessageProperty.Address;
    
            var hostEntry = Dns.GetHostEntry(hostName);
            hostName = hostEntry.HostName;
        }
        catch
        {
        }
    
        return hostName;
    }
    

    是的,我知道代码目前不干净(空catch等),这是目前概念的证明…

    1 回复  |  直到 14 年前
        1
  •  1
  •   Darin Dimitrov    14 年前

    那是不可能的。您所希望得到的只是调用者的IP地址,当然还有请求消息和最终HTTP头中包含的任何信息。