My goal is to develop an application in VB.NET that monitors eDirectory
using an LDAP persistent search. As user objects are added, moved,
renamed and deleted in eDirectory, the program will construct an event
notification in XML format and send it to an email account for
processing by other programs.

I've tried implementing the above functionality using the now
unsupported Novell Internet Directory ActiveX control (NWIDir), which
supports a PersistentSearch method and change notification via a
DirectoryModified event. But have found that it will only run for a few
minutes and then crashes either when run in the VB6 IDE or as an
executable. Since the these ActiveX controls are now unsupported (a
real shame, since they offer AMAZING functionality and INCREDIBLE ease
of use), I decided to go with a pure VB.NET solution.

I settled on using the System.DirectoryServices.protocols name space
and have tried to implement a persistent search with the following code:

************************************************** *******
Dim error_message As String = ""
Dim ldapcon As LdapConnection = LDAP_Connect(error_message)

If ldapcon Is Nothing Then
'Failed to connect to the ldap server.
MessageBox.Show("Failed to connect to ldap server,
Exception: " & error_message)
Exit Sub
End If
Dim attributesList() As String = {"cn", "SSN", "sn",
"givenname", "initials", "l", "ou", "telephonenumber",
"facsimiletelephonenumber", "title", "description", "uid",
"logindisabled", "logintime", "passwordexpirationtime",

Dim ctrlData As Byte() = BerConverter.Encode("{ibb}", New
Object() {1, True, True})

Dim persistentSearchControl As New
DirectoryControl("2.16.840.1.113730.3.4.3", ctrlData, True, True)
Dim searchRequest As New SearchRequest("o=oes",
System.DirectoryServices.Protocols.SearchScope.Sub tree, attributesList)

searchRequest.Controls.Add(persistentSearchControl )
Dim asyncCallBack As New AsyncCallback(AddressOf
Dim timeSpan As New TimeSpan(1, 0, 0, 0, 0)

ldapcon.BeginSendRequest(searchRequest, timeSpan,
PartialResultProcessing.ReturnPartialResults, asyncCallBack,
************************************************** ******
Here's my Asynch callback subroutine definition:

Sub PersistentSearchCallBack(ByVal ar As IAsyncResult)

End Sub

Here's my function library that I developed for connecting to
eDirectory VIA SSL just for reference:

Function LDAP_Connect(ByRef Error_Message As String) As
'This function connects to an LDAP server and returns an
LDAPConnection object.
'If a connection cannot be established, the function will
return Nothing, and the
'Error_Message parameter will be set to the error returned by
the LDAP server.
Error_Message = ""

Dim ldapcon As LdapConnection = New LdapConnection(New
LdapDirectoryIdentifier(LDAP_Server_IP & ":" & LDAP_Port), New
System.Net.NetworkCredential(LDAP_Authentication_D N, ldap_Password))
ldapcon.SessionOptions.SecureSocketLayer = True
ldapcon.SessionOptions.VerifyServerCertificate = New
VerifyServerCertificateCallback(AddressOf ServerCallback)
ldapcon.AuthType = AuthType.Basic
Return ldapcon
Catch ex As Exception
'Failed to bind to ldap server.
Error_Message = ex.Message.ToString
Return Nothing
End Try
End Function

Public Function ServerCallback(ByVal connection As LdapConnection,
ByVal certificate As
System.Security.Cryptography.X509Certificates.X509 Certificate) As
'Validate that the exchanged public keys match each other.
Dim expectedCert As X509Certificate = New

If expectedCert.GetRawCertDataString =
certificate.GetRawCertDataString Then
Return True
Return False
End If
Catch ex As Exception
'Certificate could not be loaded.
Return False
End Try
End Function

When I run the code, I get an the following error message:

The server does not support the control. The control is

Any help from someone who has successfully done an LDAP persistent
search against eDirectory using the System.DirectoryServices.Protocols
name space would be greatly appreciated, I've been trying to figure this
out in my spare time for a few weeks now. Thanks in advance!

jstaffor's Profile:
View this thread: