c# - 错误 0x80005000 和 DirectoryServices

标签 c# .net wcf active-directory directoryservices

我正在尝试使用 .Net 中的目录服务运行简单的 LDAP 查询。

    DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://someserver.contoso.com/DC=contoso,DC=com");
    directoryEntry.AuthenticationType = AuthenticationTypes.Secure;

    DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry);

    directorySearcher.Filter = string.Format("(&(objectClass=user)(objectCategory=user) (sAMAccountName={0}))", username);

    var result = directorySearcher.FindOne();
    var resultDirectoryEntry = result.GetDirectoryEntry();

    return resultDirectoryEntry.Properties["msRTCSIP-PrimaryUserAddress"].Value.ToString();

我得到以下异常:

System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)
  at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
  at System.DirectoryServices.DirectoryEntry.Bind()
  at System.DirectoryServices.DirectoryEntry.get_AdsObject()
  at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
  at System.DirectoryServices.DirectorySearcher.FindOne()

作为控制台应用程序中的一个片段,这是可行的。但是当我将它作为 WCF 服务的一部分运行时(在相同的凭据下运行),它会抛出上述异常。

有什么建议吗?

谢谢

最佳答案

我一次又一次地遇到同样的问题,但似乎没有任何帮助。

将路径从 ldap:// 更改为 LDAP:// 就可以了。

关于c# - 错误 0x80005000 和 DirectoryServices,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1722398/

相关文章:

c# - WCF 服务返回另一个服务(服务工厂?)

wcf - WCF 是否支持异步操作在 TransactionScope 内调用?

c# - 如何处理 System.Drawing.Color <--> System.Windows.Media.Color 模糊引用

c# - 您如何在 WPF 中仅检查 Visual Studio 2010 设计器(以便不针对 Blend 的设计器)?

c# - 是否可以为我的所有对象创建一个通用的 Repository 类?

c# - 在卸载期间(卸载前)从自定义安装程序获取对 AppSettings 的访问权限

c# - ServiceStack接收大数据时抛出StackOverflowException

c# - ActionLink 显示错误的网址

c# - NAudio PlaybackState 永不停止?

wcf - ORM 抽象传统数据库加 WCF 服务