如何检查两个端点地址是否相同?
我的程序是一个WCF服务,它发布多种方法并有多个客户端。它将客户列表存储在数据库中。在某些方法中,我需要从数据库查询调用者的数据。这个问题服务如何知道调用者?以及链接的答案获取WCF 中的客户端地址 显示了如何获取调用者的 IP。但是,通常我的客户端表中的地址字段没有 IP,而是类似以下内容:
http://localhost:80/
http://computerName:80/
http://computerName.domain.com:80/
哪些是有效的端点地址。假设我使用链接答案中的解决方案,并且获得了调用者的 IP(例如 http://192.80.212.21:80/
)。但是在数据库中,客户端存储为 http://computerName:80/
我如何检查这两个地址是否相同,以便我可以从数据库中获取相应客户端的条目?
客户端的数量非常少,因此迭代数据库中每一行的性能问题可以忽略不计。
My program is a WCF service which publishes several methods and have multiple client. It store list of clients in the database. In some of the methods I need to query the caller's data from the database. This question How can service know the caller? and the linked answer Get the Client’s Address in WCF shows how to get the IP of the caller. However, normally the address field in my clients table don't have IP, but stuff like:
http://localhost:80/
http://computerName:80/
http://computerName.domain.com:80/
Which are valid endpoint addresses. Let's imagine I use the solution in the linked answer, and I get the IP of my caller (say http://192.80.212.21:80/
). However in the database, the client is stored as http://computerName:80/
How can I check that these two addresses are the same, so that I can get the corresponding client's entry from the database?
The number of clients is very small, so performance issue from iterating every row in the database can be negligible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须执行 DNS 查找来确定与客户端 IP 地址关联的主机名:
此时您可以将获取的
clientUri
与存储在数据库。You'll have to do a DNS lookup to determine the host name that's associated the client's IP address:
At that point you can match the obtained
clientUri
to the addresses stored in the database.