0

I need to use SSL t make a connection to the server

description : I'm working on a windows Application Project in which we use "Web Service" to communicate data with the db . the server side services are written in Java and I am doing the UI part in C#.Now I want to use SSL to have a secure connection with the server, but I can't find a way to Skip the warning message that is produced when trying to make a connection (using c# code).

a sample would help me a lot,

this is the code I use :

public bool UserLogIn ( User user )
    {
        logon logIn = new logon();

        logIn.arg0 = new userAthenticationRq();
        logIn.arg0.credential = GetCredential(user);
        logIn.arg0.clientIpAddress = GetClientIP();
        logIn.arg0.requstDate = DateTime.Now;
        logIn.arg0.requstDateSpecified = true;
        logIn.arg0.userName = user.Name;

        logonResponse rsp = new logonResponse();

        ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateRemoteCertificate);

        rsp = service.logon(logIn);//this is where the Exception Occurs


        if (rsp.@return.statusCode == statusCodeEnum.SUCCESS)
        .
        .
        .
    }
Dan Puzey
  • 33,626
  • 4
  • 73
  • 96
shahab
  • 71
  • 1
  • 5
  • 9

1 Answers1

0

If its an error about Invalid SSL Certificates you can bypass it using this:

Add this to your code

 // callback used to validate the certificate in an SSL conversation
private static bool ValidateRemoteCertificate(object sender, X509Certificate certificate,
    X509Chain chain, SslPolicyErrors policyErrors)
{
        return true;
}

and than add this to call it and accept all certificates:

// Adds validation of SSL Certificates
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate);
Iain Ward
  • 9,850
  • 5
  • 34
  • 41
  • Thanks for the answer , I used this code but when I try to call the service I get an exception (WebException) with an error message like "The request failed with an empty response". – shahab Jul 13 '10 at 11:09
  • Are you using a https or http address? Have a look here http://bytes.com/topic/net/answers/826258-web-service-request-failed-empty-response – Iain Ward Jul 13 '10 at 11:43
  • I was using Http...when i changed it to Https It worked !!! Apparently the problem is solved. Thanks a lot – shahab Jul 13 '10 at 12:21