I have created a webservice which determines if a user exists within
edirectory 8.8. I am using the Novell.Directory.LDAP version 2.1.8.0.
The application is using .Net Framework v1.1.4322.

The service is called NovellLDAPUserExists. It has an input of a Username
and the service determines if the user exists within the organizational
unit "Users" or the organizational unit "Pending". The service is used to
prevent creating a duplicate entry via another service named
NovellLDAPCreateUser.

The service works and returns "TRUE" e if I single step through it but
returns "FALSE" if I run the app. If I put a breakpoint at the line which
reads 'if (lsc.Count !=0), lsc.Count will = 0. If I wait a few seconds,
lsc.Count will change to a 1. My understanding is that the call I am
using is synchronous and lsc.Count should contain a valid number.

Here is the code I have created:

[WebMethod]
public string NovellLDAPUserExists(string UserToSearchFor)
{
string ldapHost = "xxx.xxx.xxx.xxx";
int ldapPort = 389;
String loginDN = "<place your fully qualified admin name here ie.
cn=admin, OU=admingroup, O=MainTree>";
String password = "<place your admin password here>";
String searchFilter = "(objectclass=inetOrgPerson)";
string[] attributesToReturn = new string[] { "cn" };
string txtUserFound = "FALSE";
try
{
Novell.Directory.Ldap.LdapConnection conn = new Novell.Directory.Ldap.
LdapConnection();
conn.Connect(ldapHost, ldapPort);
conn.Bind(loginDN, password);
// Create a constraints control
LdapSearchConstraints cons = conn.SearchConstraints;
// Set the maximum number of records to be returned by search
cons.MaxResults = 10;
conn.Constraints = cons;

// Determine if user exists within "ou=users,o=workforce"
LdapSearchResults lsc = conn.Search("cn=" + UserToSearchFor +
",ou=users,o=workforce",
Novell.Directory.Ldap.LdapConnection.SCOPE_BASE,
searchFilter,
attributesToReturn,
false);
if (lsc.Count != 0)
{
txtUserFound = "TRUE";
}
else
{
// Determine if user exists within "ou=pending,o=workforce"
lsc = conn.Search("cn=" + UserToSearchFor + ",ou=pending,o=workforce",
Novell.Directory.Ldap.LdapConnection.SCOPE_BASE,
searchFilter,
attributesToReturn,
false);

// If nextEntry not null then a user was found
if (lsc.Count != 0)
{
txtUserFound = "TRUE";
}
}

conn.Disconnect();
return txtUserFound;

}
catch (Novell.Directory.Ldap.LdapException e)
{
return "Error:" + e.LdapErrorMessage;
}
catch (Exception e)
{
return "Error:" + e.Message;
}
}

Are there any other C# routines which I can use to determine if a user
exists in a given group?
Is there a problem in my code? Am I not calling the search function
synchronously?
Has anyone experienced a problem like this?