【问题标题】:WCF Security - Data origin securityWCF 安全 - 数据源安全
【发布时间】:2009-09-08 05:11:18
【问题描述】:

我在 WCF 中实现了一个 Web 服务。此服务只会被单个客户端调用,即具有静态 IP 地址的站点。我想实现简单的安全性,以验证对服务的所有调用仅在来自此特定静态 IP 时才有效。

最好的方法是什么?

【问题讨论】:

    标签: .net wcf security wcf-security


    【解决方案1】:

    在 .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;
    }
    

    最初见于 Keyvan Nayyeri 的 blog post

    马克

    【讨论】:

    • 我希望使用 config,而不是代码,但如果无法使用 config,这肯定会成功。感谢您的回答。
    • 据我所知,没有办法根据配置中的 IP 来限制调用者,对不起。
    猜你喜欢
    • 2010-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    相关资源
    最近更新 更多