如何检查两个端点地址是否相同?

发布于 2025-01-08 05:39:47 字数 694 浏览 0 评论 0原文

我的程序是一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡看悲欢离合 2025-01-15 05:39:47

您必须执行 DNS 查找来确定与客户端 IP 地址关联的主机名:

var clientEndpoint = OperationContext.Current
    .IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
var clientHostName = Dns.GetHostEntry(clientEndpoint.Address).HostName;
var clientPort = clientEndpoint.Port;

var clientUri = new UriBuilder("http", clientHostName, clientPort).ToString();

此时您可以将获取的 clientUri 与存储在数据库。

You'll have to do a DNS lookup to determine the host name that's associated the client's IP address:

var clientEndpoint = OperationContext.Current
    .IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
var clientHostName = Dns.GetHostEntry(clientEndpoint.Address).HostName;
var clientPort = clientEndpoint.Port;

var clientUri = new UriBuilder("http", clientHostName, clientPort).ToString();

At that point you can match the obtained clientUri to the addresses stored in the database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文