Anonymous_User Absent Member.
Absent Member.
3641 views

C# System.Net.Sockets.SocketException

We downloaded C# DLL's from Novel and use sample C# code , unfortunately we are System.Net.Sockets.SocketException error on the bind .
We validated using Softerra LDAP Browser that we can establish successful connection to the server using same settings and user.
LdapErrorMessage:
Message: Connect Error
InnerException:
Cause.Message: Unable to read data from the transport connection: An existing co
nnection was forcibly closed by the remote host.
Cause.InnerException: System.Net.Sockets.SocketException (0x80004005): An existi
ng connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size,
SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 s
ize)
Cause.StackTrace: at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int
32 offset, Int32 size)
at System.IO.Stream.ReadByte()
at Novell.Directory.Ldap.Asn1.Asn1Identifier..ctor(Stream in_Renamed)
at Novell.Directory.Ldap.Connection.ReaderThread.Run()
Labels (1)
0 Likes
5 Replies
Knowledge Partner
Knowledge Partner

Re: C# System.Net.Sockets.SocketException

What does your code look like?

Have you tried binding anonymous?

What is the LDAP implementation to which you are connecting and does it
have any information on the disconnect?

Which socket (IP/port) are you using for your connection, and are you
specifying to use the STARTTLS extension or SSL, if applicable?

Apache Directory Studio is a great LDAP browser/editor that's
cross-platform and available for free. Give it a shot and note the
specific of your connection when setting it up, for example which port,
the user DN syntax, the security options chosen, etc.

--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...
0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: C# System.Net.Sockets.SocketException

We are using code similar to example on the Novell site .
As I stand in the comment we validated via free browser from Softera .
in particular our code is from sample ftp://sdk.provo.novell.com/ndk/ldapcsharp/Samples/Samples/SecureBind.cs
port 636
...
conn= new LdapConnection();
conn.SecureSocketLayer=true;
Console.WriteLine("Connecting to:" + ldapHost);
conn.Connect(ldapHost,ldapPort);
conn.Bind(loginDN,password);
Console.WriteLine(" SSL Bind Successfull");
...
0 Likes
Knowledge Partner
Knowledge Partner

Re: C# System.Net.Sockets.SocketException

Depending on how far you made it, chances are good that your connection is
failing because the client side (your code) does not trust the certificate
presented by the server side (LDAP service). You'll need to work out how
to trust that certificate in whatever way C# does that. With Java you'd
import the CA's (and possibly intermediate certificate's) trusted root
public key certificate into a truststore used by your application.

A LAN trace would likely show an SSL alert if this is the case, so if you
can get one and post it somewhere, that should help confirm the theory.

--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...
0 Likes
Anonymous_User Absent Member.
Absent Member.

Re: C# System.Net.Sockets.SocketException

correction
I place exact code from the ftp://sdk.provo.novell.com/ndk/ldapcsharp/Samples/Samples/SecureBind.cs
and compile it
execute it like :
myapp.exe myhost 636 "CN=user,ou=ServiceAccounts,ou=xxx,o=yyy" somepassword

Detected errors in the Server Certificate:
-2146762481
-2146762486
Error:SSL handshake failed

but same credentials and config works with free browser from Softera .
0 Likes
Dieseloreo
New Member.

Re: C# System.Net.Sockets.SocketException

I know this is a old post, but though I would put some more bread crumbs for future searchers.

I was just playing with the c# code as well and had issue.

My issue was that I didn't do the following.

1. add the nugget package mono.security
2. set the certificate acceptance before the connection.
3. and I set a default accept all certificates with the certificate delegate call to true
conn.UserDefinedServerCertValidationDelegate += delegate { true; };
4. ensure all ssl items are set for the connect line
conn.Connect(ldapHost,ldapPort)



I couldn't figure out where the mono certificate store was put and when I imported a cert on windows(mono not windows import), it never seemed to work. So I bypassed the certificate check all together with the delegate true line.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.