Discussion:
The LDAP server is unavailable
(too old to reply)
Florin
2009-01-30 06:11:01 UTC
Permalink
Hello,

I try to use System.DirectoryServices.Protocols to connect to an LDAP
server (Oracle Internet Directory) from C#. The LDAP server is behind a
firewall (port open in the firewall) and is configured to listen on 1636
using SSL server certificate. I am able to use a number of tools (JExplorer,
ldapsearch or ldapbind) to interogate the LDAP server.

I use the following code:

//////////////////
string hostOrDomainName = "admedi02.conext.europa.eu:1636";
string targetOu = "cn=Users,dc=conext,dc=europa,dc=eu";
string userName = "042065";
string password = "042065";

// create a search filter to find all objects
string ldapSearchFilter = "cn=" + userName;
string userOracleRealm = "cn=" + userName + "," +
"cn=Users,dc=conext,dc=europa,dc=eu";

NetworkCredential cred = new NetworkCredential(userOracleRealm,
password);

// establish a connection to the directory
LdapDirectoryIdentifier direct = new
LdapDirectoryIdentifier(hostOrDomainName);
LdapConnection connection = new LdapConnection(direct, cred,
AuthType.Basic);

connection.SessionOptions.ProtocolVersion = 3;
connection.SessionOptions.SecureSocketLayer = true;

connection.Bind();

////////////////////


The bind fails with the message:

System.DirectoryServices.Protocols.LdapException was unhandled
Message="The LDAP server is unavailable."
Source="System.DirectoryServices.Protocols"
ErrorCode=81
StackTrace:
at System.DirectoryServices.Protocols.LdapConnection.Connect()
at
System.DirectoryServices.Protocols.LdapConnection.BindHelper(NetworkCredential newCredential, Boolean needSetCredential)
at System.DirectoryServices.Protocols.LdapConnection.Bind()
at CDBUtils.Form1.button1_Click(Object sender, EventArgs e) in
D:\CDBUtils\CDBUtils\Form1.cs:line 157
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at CDBUtils.Program.Main() in D:\CDBUtils\CDBUtils\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

What could be the problem? Is there a better forum (a special one for
S.DS.P) for than this one for posting my question?

Thanks,
Florin
Joe Kaplan
2009-01-30 15:42:51 UTC
Permalink
If you implement a VerifyServerCertificateCallback that returns true and
assign that to the proper member on your session options member on your
connection, does that make the problem go away?

It could be that there is an SSL trust problem with the remote server's SSL
certificate. The default behavior in Windows is to fail when negotiating
SSL and there is a problem during chain verification. Implementing this
callback allows you to ignore verification problems or at least perform the
chain verification yourself so you can ignore some problems but fail on
others.

As to why other tools might choose to ignore SSL problems, I can't tell you.

There may also be an error in the system event log from the schannel
provider that shows details of this failure if this is the problem. If
there is, the error code recorded will describe the exact nature of the
problem.
--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
Post by Florin
Hello,
I try to use System.DirectoryServices.Protocols to connect to an LDAP
server (Oracle Internet Directory) from C#. The LDAP server is behind a
firewall (port open in the firewall) and is configured to listen on 1636
using SSL server certificate. I am able to use a number of tools (JExplorer,
ldapsearch or ldapbind) to interogate the LDAP server.
//////////////////
string hostOrDomainName = "admedi02.conext.europa.eu:1636";
string targetOu = "cn=Users,dc=conext,dc=europa,dc=eu";
string userName = "042065";
string password = "042065";
// create a search filter to find all objects
string ldapSearchFilter = "cn=" + userName;
string userOracleRealm = "cn=" + userName + "," +
"cn=Users,dc=conext,dc=europa,dc=eu";
NetworkCredential cred = new NetworkCredential(userOracleRealm,
password);
// establish a connection to the directory
LdapDirectoryIdentifier direct = new
LdapDirectoryIdentifier(hostOrDomainName);
LdapConnection connection = new LdapConnection(direct, cred,
AuthType.Basic);
connection.SessionOptions.ProtocolVersion = 3;
connection.SessionOptions.SecureSocketLayer = true;
connection.Bind();
////////////////////
System.DirectoryServices.Protocols.LdapException was unhandled
Message="The LDAP server is unavailable."
Source="System.DirectoryServices.Protocols"
ErrorCode=81
at System.DirectoryServices.Protocols.LdapConnection.Connect()
at
System.DirectoryServices.Protocols.LdapConnection.BindHelper(NetworkCredential
newCredential, Boolean needSetCredential)
at System.DirectoryServices.Protocols.LdapConnection.Bind()
at CDBUtils.Form1.button1_Click(Object sender, EventArgs e) in
D:\CDBUtils\CDBUtils\Form1.cs:line 157
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at CDBUtils.Program.Main() in D:\CDBUtils\CDBUtils\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
What could be the problem? Is there a better forum (a special one for
S.DS.P) for than this one for posting my question?
Thanks,
Florin
Loading...