识别 WCF 客户端 ID
我有一个公开多种业务方法的 WCF Web 服务。我还有两个客户端 - 一个 asp.net GUI 和一个数据迁移应用程序,它们都连接到 wcf 后端以调用各种业务事务。
我需要我的后端能够识别和区分哪个 wcf 客户端调用了某些变体逻辑。
有没有办法让我的 WCF 服务能够识别连接到它的客户端?还有没有办法使用签名密钥来防止客户端欺骗其身份?
I have a WCF web service that exposes several business methods. I also have two clients - an asp.net GUI and a data migration application that both connect to the wcf backend to invoke various business transactions.
I need my backend to be able to identify and distinguish between which wcf client has made a call to some variant logic.
Is there a way that my WCF service is able to identify clients connected to it? Also is there a way to use a signed key to prevent a client from spoofing their identity?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过自定义标头解决此问题。
您可以添加自定义标头作为客户端应用程序配置文件中端点的一部分。然后,您可以使每个客户端的自定义标头不同。例如,在 ASP.NET 版本中:
然后服务可以像这样检查标头值:
You can solve this via a custom header.
You can add a custom header as part of the endpoint in the client application's configuration file. You would then make each client's custom header different. For example, in the ASP.NET version:
Then the service can check the header value like so:
为了识别调用者的类型(ASP.NET 与 WInforms 或其他),您可能需要向 WCF 消息添加自定义标头 - 服务无法了解有关调用客户端的任何信息,除非它是消息的一部分或发送的标头。为此,最好的选择是编写一个 WCF 消息检查器 - 以及这个 此处的博客文章将向您展示如何执行此操作。
至于安全性 - 取决于您的环境。在防火墙后面的公司 LAN 中 - 使用 Windows 凭据。如果您“面向外部”,最好的选择是在客户端上安装数字证书以验证其身份。
WCF 大师 Juval Löwy 在 MSDN 杂志上发表了一篇非常好的文章,声明性 WCF 安全,描述了 WCF 中的五种常见安全场景以及如何实现它们。强烈推荐阅读。
In order to identify the type of caller (ASP.NET vs. WInforms or whatever), you probably need to add a custom header to your WCF messages - there's no way the service can know anything about the calling client unless it's part of the message or the headers sent. For this, your best bet is to write a WCF Message Inspector - and this blog post here will show you how to do this.
As for security - depends on your environment. In a corporate LAN behind a firewall - use the Windows credentials. If you're "outside facing", your best bet would be to install digital certificates on the clients to verify their identity.
WCF Guru Juval Löwy has a really good article on MSDN Magazine, Declarative WCF Security, that describes five common security scenarios in WCF and how to implement them. Highly recommended reading.