2009-09-08 152 views
0

我有一个WCF实现的Web服务。这项服务只会由一个客户端(一个拥有静态IP地址的站点)调用。我希望实现简单的安全性,以验证所有对该服务的调用只有在来自此特定静态IP时才有效。WCF安全 - 数据来源安全

这样做的最好方法是什么?

回答

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

马克

+0

我希望与配置,而不是代码来完成,但是这肯定会做的伎俩,如果没有办法与配置做到这一点。感谢你的回答。 – Odd 2009-09-08 23:08:54

+0

据我所知,没有办法根据配置中的IP限制呼叫者,对不起。 – 2009-09-09 04:57:23