相关疑难解决方法(0)

错误0x80005000和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();
Run Code Online (Sandbox Code Playgroud)

我得到以下例外:

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()
Run Code Online (Sandbox Code Playgroud)

作为控制台应用中的代码段,这是有效的.但是,当我将其作为WCF服务的一部分运行(在相同的凭据下运行)时,它会抛出上述异常.

有什么建议?

谢谢

.net c# wcf directoryservices active-directory

40
推荐指数
6
解决办法
10万
查看次数

标签 统计

.net ×1

active-directory ×1

c# ×1

directoryservices ×1

wcf ×1