Florin
2009-01-30 06:11:01 UTC
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
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