Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's a permission problem.</p> <p>When you run the console app, that app runs with your credentials, e.g. as "you".</p> <p>The WCF service runs where? In IIS? Most likely, it runs under a separate account, which is not permissioned to query Active Directory.</p> <p>You can either try to get the WCF impersonation thingie working, so that your own credentials get passed on, or you can specify a username/password on creating your DirectoryEntry:</p> <pre><code>DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://someserver.contoso.com/DC=contoso,DC=com", userName, password); </code></pre> <hr> <p>OK, so it might not be the credentials after all (that's usually the case in over 80% of the cases I see).</p> <p>What about changing your code a little bit?</p> <pre><code>DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry); directorySearcher.Filter = string.Format("(&amp;(objectClass=user)(objectCategory=user) (sAMAccountName={0}))", username); directorySearcher.PropertiesToLoad.Add("msRTCSIP-PrimaryUserAddress"); var result = directorySearcher.FindOne(); if(result != null) { if(result.Properties["msRTCSIP-PrimaryUserAddress"] != null) { var resultValue = result.Properties["msRTCSIP-PrimaryUserAddress"][0]; } } </code></pre> <p>My idea is: why not tell the <code>DirectorySearcher</code> right off the bat what attribute you're interested in? Then you don't need to do another extra step to get the full <code>DirectoryEntry</code> from the search result (should be faster), and since you told the directory searcher to find that property, it's certainly going to be loaded in the search result - so unless it's null (no value set), then you should be able to retrieve it easily.</p> <p>Marc</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload