Fixed it. Luckily I found this article that explains the System.DirectoryServices.Protocols namespace. Unfortunately there was a problem with the certificate issuer name and therefore my task kept failing.
The code that fixed it is below. The main item was the VerifyServerCertificate portion where I could override the issue of having different names on the certificate issuer and the server I was connecting to. That method is at the bottom of the listing:
Dim ldi As LdapDirectoryIdentifier = New LdapDirectoryIdentifier(ldap-1.areaname.com)
Dim myUserName As String = String.Format("uid={0},ou=People,dc=areaname,dc=com", username)
Dim creds As System.Net.NetworkCredential = New System.Net.NetworkCredential(myUserName, password)
Dim conn As LdapConnection = New LdapConnection(ldi, creds)
Dim response As SearchResponse = Nothing
Dim anEntry As SearchResultEntry = Nothing
Dim isUserFound As Boolean = False
conn.SessionOptions.ProtocolVersion = 3
conn.SessionOptions.SecureSocketLayer = True
conn.AuthType = AuthType.Basic
conn.SessionOptions.VerifyServerCertificate = New VerifyServerCertificateCallback(AddressOf ServerCertificateRoutine)
Dim filter As String = String.Format("uid={0}", username)
Dim aRequest As SearchRequest = New SearchRequest("OU=People,DC=areaname,DC=com", filter, SearchScope.Subtree)
Try
conn.Bind()
response = conn.SendRequest(aRequest)
anEntry = response.Entries(0)
If anEntry.Attributes.Count > 0 Then
isUserFound = True
Else
isUserFound = False
End If
Catch ldapEx As LdapException
'this is thrown when the connection fails
isUserFound = False
Catch ex As Exception
isUserFound = False
Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "General")
If rethrow Then
Throw
End If
End Try
Return isUserFound Private Shared Function ServerCertificateRoutine(ByVal conn As LdapConnection, ByVal cert As X509Certificate)
'This ignores any errors from the certificate
Return True
End Function
Hope this helps others who have hit this.
Matt