all groups > dotnet web services > march 2006 >
You're in the

dotnet web services

group:

Using LDAP in a web service


Using LDAP in a web service Chris Kormann
3/27/2006 9:01:07 AM
dotnet web services:
I am attempting to use LDAP to retrieve a list of users from within a web
service. When the FindAll() method is invoked, I receive the following
exception: "The specified domain either does not exist or could not be
contacted."

The code that does not work from within the web service works fine from
within a Windows forms application, so my first guess is that the issue is
security related.

Any ideas on how to use LDAP from within a web service?

Thanks for your help.

Chris

Here is the relevant code from the web service:

DirectorySearcher ds = new DirectorySearcher();
ds.SearchRoot = new DirectoryEntry(""); // start searching from local domain
ds.Filter = String.Format("(&(objectCategory=user)(name={0}))",
txtUserName.Text);
ds.PropertyNamesOnly = true;
ds.PropertiesToLoad.Add("name");
ds.PropertiesToLoad.Add("SAMAccountName");
ds.SearchScope = SearchScope.Subtree;
ds.CacheResults = false;
ds.ReferralChasing = ReferralChasingOption.None;
ds.Sort = new SortOption("name", SortDirection.Ascending);

// start searching
Re: Using LDAP in a web service Chris Kormann
3/27/2006 11:11:02 AM
Thanks Marc, I think that did it.

Chris

[quoted text, click to view]
Re: Using LDAP in a web service Marc Scheuner
3/27/2006 8:47:06 PM
[quoted text, click to view]

This either means your LDAP path is invalid (but since you didn't
specify any, that's not likely :-), or then you have an issue with
permissions (most likely). Most likely, the user context the web
service runs under is not privileged to reach into your corporate AD.

I would assume that if used from a web service, you'll need to provide
explicit credentials to use in your LDAP query. You can do this by
instantiating the DirectoryEntry for the root of your search
separately:

DirectorySearcher ds = new DirectorySearcher();

DirectoryEntry deRoot = new
DirectoryEntry("LDAP://yourserver01.yourdomain.com/ou=SomeOU,dc=yourdomain,dc=com",
"your user name", "your user password", AuthenticationTypes.Secure);

ds.SearchRoot = deRoot;
and so forth....

Provided that user you specify is privileged enough to query the AD,
you should be able to run this code and get data back.

AddThis Social Bookmark Button