Bonjour,

J'ai un projet dans lequel j'accède à un web service. Cette connexion à récemment évoluée et est basée sur une connexion Https avec certificat et user/ mot de passe.

Dans un premier temps je ne devais utiliser que le certificat et cela fonctionnait:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
String soapRequest = ESBManager.Read(TPL.SOAP_REQUEST);
                soapRequest = String.Format(soapRequest, orderRequest);
 
                byte[] buffer = Encoding.ASCII.GetBytes(soapRequest);
 
                X509Certificate Cert = X509Certificate.CreateFromCertFile(Configuration.GetConfigurationVariable("esb.certificate"));
 
                HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("https://xxxx");
 
                WebReq.ClientCertificates.Add(Cert);
 
                //The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
 
                // Elargissement du timeout
                WebReq.Timeout = 300000;
                //Set the method/action type
                WebReq.Method = "POST";
                //We use form contentType
                WebReq.ContentType = "soap/xml; charset=utf-8";
 
                //The length of the buffer
                WebReq.ContentLength = buffer.Length;
 
                //We open a stream for writing the post  data
                Stream MyPostData = WebReq.GetRequestStream();
 
                //Now we write, and after wards, we close. Closing is always important!
                MyPostData.Write(buffer, 0, buffer.Length);
                MyPostData.Close();
 
                //Get the response handle, we have no true response yet!
                HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
 
                //Now, we read the response (the string), and output it.
                Stream MyResponse = WebResp.GetResponseStream();
                StreamReader MyResponseReader = new StreamReader(MyResponse);
 
                //Read the response Stream and write it
                String response = MyResponseReader.ReadToEnd();
                return response;
Si mon certificat était Ok alors ma requête passait sinon j'avais bien une erreur.

Depuis je dois tester ma connexion avec le certificat et un user/mot depasse j'ai donc voulu utiliser WebRequest.Credetial en ajoutant:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
                string esbUser = Configuration.GetConfigurationVariable("esb.user");
                string esbPassword = Configuration.GetConfigurationVariable("esb.password");
 
                WebReq.UseDefaultCredentials = false;
                WebReq.Credentials = new NetworkCredential(esbUser, esbPassword);
Mais quand je teste peu importe les valeur de user/password ma requête est toujours OK...

Du coup on me documentant un peu plus sur ce sujet que je ne maîtrise pas je n'ai pas l'impression que les deux solutions existent ensemble mais plutot que c'est soit l'une soit l'autre. Du coup je ne comprend pas la demande d'évolution de ce service.

Quelqu'un pourrait m'aider à comprendre?

Cordialement,
Christophe.