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

有没有办法让WCF服务知道调用来自哪台机器?

  •  1
  • erxuan  · 技术社区  · 15 年前

    我有一个WCF服务,在客户端不更改任何代码的情况下,有没有一种方法可以知道调用方的详细信息,如machinename和applicationname?

    基本上,我不能更改客户机代码来传递这些信息。

    我试图在服务器端使用system.web.httpcontext来跟踪此信息,但httpcontext.current为空。我想这不是正确的用法。

    有什么建议吗?

    谢谢 莎拉

    2 回复  |  直到 15 年前
        1
  •  2
  •   erxuan    15 年前

    我通过这篇文章找到了答案: Client IP addresses in Orcas .

    下面是一段代码(使用.NET 3.5):

    // Track the IP address and port of the calling client
    OperationContext context = OperationContext.Current;
    MessageProperties properties = context.IncomingMessageProperties;
    RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
    Trace.TraceInformation("Receive a document from {0}:{1} via {2}", endpoint.Address, endpoint.Port, properties.Via.AbsoluteUri);
    
        2
  •  0
  •   blowdart    15 年前

    您可以在WCF 3.5中获取IP地址,但仅此而已(将duplex服务放在一边,在此期间您可以获取返回URL)