quillbreaker
quillbreaker

Reputation: 6215

Calling HTTPS JBoss service from C# code throws an authentication error

I'm trying to call a JBoss service from a C# program and I'm getting an annoyingly vague error.

            JbossService proxy = new JbossService();
            proxy.Credentials = new NetworkCredential("ME", "thepwd");
            proxy.Url = //https url snipped
            proxy.CookieContainer = new CookieContainer();
            proxy.PreAuthenticate = true;

            Console.WriteLine("Calling service...");
            queryResponse qr = proxy.query();
            Console.WriteLine("Done.");

The exception and inner exception thrown are as follows:

exception : The underlying connection was closed: An unexpected error occurred on a send.

inner exception : Authentication failed because the remote party has closed the transport stream.

I'm not quite sure what this means, other than perhaps that JBoss likes me even less than I like it. I'm calling from the local machine so I don't think it's a networking issue. Has anyone seen this before?

Upvotes: 2

Views: 1419

Answers (2)

Joe Enzminger
Joe Enzminger

Reputation: 11190

This usually happens when your client cannot verify trust over https with the server (usually because the server certificate is self signed or if it is signed by a root authority not installed on your client machine.

Easy fix (although there are security consequences)....somewhere in your initialization code add the following:

System.Net.ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => { return true;};

Basically this replaces the application wide handling of server certificate validation and causes your application to accept any certificate. If you want to get finer grained, you can examine the certificate and put some logic in the method.

This works for anything based on System.Net, so it should work for Web Services and any thing based on WebRequest.

Upvotes: 3

Mike Christian
Mike Christian

Reputation: 1536

I haven't used JBOSS. This is how I troubleshoot similar problems, when using Microsoft technologies -- the same issues may be affecting your program:

  • Firewall settings or network issue (try connecting manually, to rule this out)
  • Self-service certificate issues:
    • Check the following certificate values:
      • Ensure the server's certificate issuer has a valid, matching issuing trusted root Certificate Authority (CA), on the same machine
      • The server certificate subject name matches the machine name exactly
      • The machine name the client is accessing matches that defined in the server certificate
      • An administrator account set (server) certificate thumbprint
    • Try recreating the SSL Certificate on both servers)
    • Try creating your own CA cert, add to trusted publishers, and then create an SSL sert based on that

Upvotes: 1

Related Questions