Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / March 2006

Tip: Looking for answers? Try searching our database.

Using LDAP in a web service

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Kormann - 27 Mar 2006 18:01 GMT
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
SearchResultCollection src = ds.FindAll();
Marc Scheuner - 27 Mar 2006 19:47 GMT
>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."

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.

Marc
Chris Kormann - 27 Mar 2006 20:11 GMT
Thanks Marc, I think that did it.

Chris

> >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
[quoted text clipped - 24 lines]
>
> Marc

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.