Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

[WD9] sélection certificat SSL : traduction .NET C# => WinDev ou utilisation d'un assembly

1 réponse
Avatar
JeAn-PhI
bonjour

j'ai le code en C# pour sélectionner et valider automatiquement un
certificat SSL qq'un pourrait m'aider soit à traduire le code en WinDev
soit utiliser l'assembly .NET qui va bien.
si il manque des infos merci de me le faire savoir

merci d'avance

[code]
private void button1_Click(object sender, System.EventArgs e)
{
//Instanciation du service web (invoke web service method using
proxy)
//
WS_Proc instance_WS_Proc = new WS_Proc();

//Redirection permettant à l'application cliente accepter
systématiquement le certificat serveur.
//
System.Net.ServicePointManager.CertificatePolicy = new
TrustAllCertificatePolicy();

//Déclaration du fichier certificat client demandé par le serveur
web et accessible par l'application
//ASN.1 DER est le seul format de certificat pris en charge par la
classe X509Certificate.
string Certificate = "nom_certif.cer";


try
{
//Lecture du certificat client sur le disque
//
X509Certificate cert =
X509Certificate.CreateFromCertFile(Certificate);

//Ajout du certificat client à l'instance du proxy du service web
//
instance_WS_Proc.ClientCertificates.Add(cert);

//Paramètre d'entrée du service web WS_NomServiceWeb
//
string XML_in = "MonFlux";

//Appel de ma méthode WS_Proc du service Web.
//
textBox1.Text = instance_WS_Proc.WS_Proc(XML_in,"user",
"password");
}
catch (WebException ex)
{
//Gestion des exceptions web
MessageBox.Show(ex.Message,"WebException");
}
catch (System.IO.FileNotFoundException ex)
{
//Gestion des exceptions sur le fichier certificat client
MessageBox.Show(ex.Message,"FileNotFoundException");
}
catch (System.Security.Cryptography.CryptographicException ex)
{
//Gestion des exceptions sur le décodage du certificat client
MessageBox.Show(ex.Message,"CryptographicException");
}
catch (Exception ex)
{
//Gestion des autres exceptions
MessageBox.Show(ex.Message,"Exception"); }
}

}

//Cette classe permet d'accepter les certificats provenant du serveur
WEB
//
public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
{
public TrustAllCertificatePolicy()
{}

public bool CheckValidationResult(ServicePoint sp,
X509Certificate cert,WebRequest req, int problem)
{
return true;
}
}
[/code]

--
Cordialement JeAn-PhI

1 réponse

Avatar
Gilles TOURREAU
Le 28/07/2006, JeAn-PhI a supposé :
bonjour

j'ai le code en C# pour sélectionner et valider automatiquement un certificat
SSL qq'un pourrait m'aider soit à traduire le code en WinDev soit utiliser
l'assembly .NET qui va bien.
si il manque des infos merci de me le faire savoir

merci d'avance

[code]
private void button1_Click(object sender, System.EventArgs e)
{
//Instanciation du service web (invoke web service method using proxy)
//
WS_Proc instance_WS_Proc = new WS_Proc();

//Redirection permettant à l'application cliente accepter systématiquement
le certificat serveur.
//
System.Net.ServicePointManager.CertificatePolicy = new
TrustAllCertificatePolicy();

//Déclaration du fichier certificat client demandé par le serveur web et
accessible par l'application
//ASN.1 DER est le seul format de certificat pris en charge par la classe
X509Certificate.
string Certificate = "nom_certif.cer";


try
{
//Lecture du certificat client sur le disque
//
X509Certificate cert = X509Certificate.CreateFromCertFile(Certificate);

//Ajout du certificat client à l'instance du proxy du service web
//
instance_WS_Proc.ClientCertificates.Add(cert);

//Paramètre d'entrée du service web WS_NomServiceWeb
//
string XML_in = "MonFlux";

//Appel de ma méthode WS_Proc du service Web.
//
textBox1.Text = instance_WS_Proc.WS_Proc(XML_in,"user", "password");
}
catch (WebException ex)
{
//Gestion des exceptions web
MessageBox.Show(ex.Message,"WebException");
}
catch (System.IO.FileNotFoundException ex)
{
//Gestion des exceptions sur le fichier certificat client
MessageBox.Show(ex.Message,"FileNotFoundException");
}
catch (System.Security.Cryptography.CryptographicException ex)
{
//Gestion des exceptions sur le décodage du certificat client
MessageBox.Show(ex.Message,"CryptographicException");
}
catch (Exception ex)
{
//Gestion des autres exceptions
MessageBox.Show(ex.Message,"Exception"); }
}

}

//Cette classe permet d'accepter les certificats provenant du serveur WEB
//
public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
{
public TrustAllCertificatePolicy()
{}

public bool CheckValidationResult(ServicePoint sp,
X509Certificate cert,WebRequest req, int problem)
{
return true;
}
}
[/code]



Tu ne pourras pas traduire du code .NET qui contient des exceptions...
En effet quand .NET déclenche une exception une exception Windev est
automatiquement déclenché mais on ne connais pas le "type" de
l'exception (WebException, FileNotFoundException,...etc)

Cordialement

--
Gilles TOURREAU
Responsable informatique


Société P.O.S
Spécialiste en motoculture depuis + de 30 ans !
http://www.pos.fr