1

I wanted to call ssl web service. I have server certificate that i installed in trusted store. I am using SOAP UI tool and soap sonar to call ssl web service i am using with htts call to the service.

Looks like certificate is not going through the request.

I have create a C# application to pass the request with certificate.

But still the same error.

Can you suggest any other tools to test webservice ? or sample code?

 private void button4_Click(object sender, EventArgs e)
    {
        try
        {

            var clientHandler = new WebRequestHandler();
            string address = @"https://xxx.xxx.xxx.xxx:58444/IVR/";
            var requestXML = "\\request.xml";
            var serialized = File.ReadAllText(Environment.CurrentDirectory + requestXML);
            var cert = GetCert();
            CertificateWebClient myWebClient = new CertificateWebClient(cert);

            string fileName = Environment.CurrentDirectory + requestXML;
            myWebClient.Headers.Add("Content-Type", "application/xml;charset=utf-8");
            byte[] responseArray = myWebClient.UploadFile(address, fileName);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }


 public class CertificateWebClient : WebClient
{
    private readonly X509Certificate2 certificate;

    public CertificateWebClient(X509Certificate2 cert)
    {
        certificate = cert;
    }

    protected override WebRequest GetWebRequest(Uri address)
    {
        HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);

        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
        request.ServicePoint.Expect100Continue = true;
        request.ServerCertificateValidationCallback =
            delegate(Object obj,
            X509Certificate X509certificate,
            X509Chain chain,
            System.Net.Security.SslPolicyErrors errors)
            {
                if (errors == System.Net.Security.SslPolicyErrors.RemoteCertificateNameMismatch)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            };

        request.ClientCertificates.Add(certificate);
        return request;
    }
}

Exceptions:-

The request was aborted: Could not create SSL/TLS secure channel.

Prashant
  • 710
  • 3
  • 7
  • 29
  • If you are getting an exception, please post it – Camilo Terevinto Jun 09 '16 at 19:38
  • I have updated question with exception. – Prashant Jun 09 '16 at 19:41
  • 1
    That's probably not related to your code. Either A: the server's certificate isn't trusted by your application; or B: your client's certificate is not accepted by the server. Check with Fiddler that you are really passing the certificate in the request – Camilo Terevinto Jun 09 '16 at 19:47
  • In fiddler i can see this error message "An unknown error occurred while processing the certificate Win32 (SChannel) Native Error Code: 0x8009032" – Prashant Jun 09 '16 at 20:01
  • in 2 way ssl do i need to pass both client and server certificate? now i am passing client certificate only. request.ClientCertificates.Add(certificate); how to pass other certificate. looks like from fidder first handshake for certification is successful but fails after that – Prashant Jun 09 '16 at 20:35

1 Answers1

0

My certificate did not have a Private Key so I created another one and installed it using how to create a private key. After that I am able to connect.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
Prashant
  • 710
  • 3
  • 7
  • 29