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

WCF安全-数据源安全

  •  0
  • Odd  · 技术社区  · 16 年前

    我在WCF中实现了一个Web服务。这个服务只能由一个客户机调用,一个具有静态IP地址的站点。我希望实现简单的安全性,以验证对服务的所有调用只有在它们来自这个特定的静态IP时才有效。

    最好的方法是什么?

    1 回复  |  直到 16 年前
        1
  •  1
  •   marc_s MisterSmith    16 年前

    在.NET 3.5上,您可以在服务代码中执行此操作以查找调用方的IP地址:

    public void YourServiceMethod(string value)
    {
       OperationContext context = OperationContext.Current;
    
       MessageProperties messageProperties = context.IncomingMessageProperties;
    
       RemoteEndpointMessageProperty endpointProperty =
           messageProperties[RemoteEndpointMessageProperty.Name]
           as RemoteEndpointMessageProperty;
    
       string clientIPAddress = endpointProperty.Address;
       int clientPort = endpointProperty.Port;
    }
    

    最初在凯文·纳耶里的 blog post .

    马克

    推荐文章