Using SSL in c# winApplication
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开发者_如何学Python 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)
.
.
.
}
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);
精彩评论