【发布时间】:2014-01-13 14:49:09
【问题描述】:
多台计算机连接到一个无线路由器。我可以在一台计算机上创建 WCF 服务,并在另一台计算机上使用该计算机的名称,如服务托管计算机上的 Environment.MachineName 所示。但是,我似乎无法从其他计算机中发现该名称。
我尝试过的一些事情:(这些只是相关的部分。)
这个:
Dns.GetHostName(); ... //(Just gives me this computer's name.)
还有这个:
PrincipalContext ctx = new PrincipalContext(ContextType.Domain) ... // "The server could not be contacted."
还有这个:
DirectorySearcher searcher = new DirectorySearcher("(objectCategory=computer)", new[] { "Name" });
SearchResultCollection SRC = searcher.FindAll(); ... // "The specified domain either does not exist or could not be contacted."
还有:
DirectoryEntry root = new DirectoryEntry("WinNT:");
foreach (DirectoryEntry dom in root.Children)
foreach (DirectoryEntry entry in dom.Children)
if (entry.Name != "Schema")
result += entry.Name + "\r\n"; // https://stackoverflow.com/a/5581339/939213 returns nothing.
那么,如何获得计算机的名称?
我对任何第 3 方库都不感兴趣。我知道http://www.codeproject.com/Articles/16113/Retreiving-a-list-of-network-computer-names-using,但该代码来自2006年。我希望现在有一些管理方法可以做到这一点。并且根据Getting computer names from my network places - “除非您确定域环境,否则不要使用 DirectoryServices”。
【问题讨论】:
-
请解释您的实际问题。查找网络上的所有计算机相对困难,而且通常不是您想要做的。你知道WCF Discovery吗?
-
@CodeCaster WCF Discovery 是一种告诉其他计算机有关 WCF 服务的方法吗?如果是这样 - 这正是我正在寻找的。我希望一台计算机能够知道还有哪些其他计算机在使用服务。
-
是的。 :-) 从该链接:“WCF 服务可以使用多播消息或发现代理服务器向网络宣布它们的可用性。客户端应用程序可以搜索网络或发现代理服务器以查找满足一组标准”.
-
@BlackICE 这看起来(至少乍一看)是一个很好的资源。虽然很长。我得看看它。谢谢。
标签: c# .net wcf networking