tags:

views:

53

answers:

1

Hello, 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 ([email protected] == statusCodeEnum.SUCCESS)
        .
        .
        .
    }
A: 

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);
w69rdy
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
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
w69rdy
I was using Http...when i changed it to Https It worked !!!Apparently the problem is solved.Thanks a lot
shahab
No problem, glad you got it working ;)
w69rdy