Bonjour,
J'ai développé une application cliente qui consomme un web service accessible uniquement par certificat client. J'ai systématiquement un échec.
Comment puis-je tracer les échanges pour analyser ?System.Net.WebException: The request failed with HTTP status 401: Unauthorized. at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at localhost.Service.outgoingTransaction(OutgoingTransactionRqstInfo req) at App_Pages_OutgoingTransaction.Page_Load(Object sender, EventArgs e)
Est-ce que la code ci-dessous est valide ?
J'ai développé deux applications avec le framework 2.0.
Un web service (asmx) qui inscrit le contenu du certificat (c'est pour les tests).
J'ai développé une application cliente qui consomme ce web service.
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 [WebMethod] public OutgoingTransactionRspsInfo outgoingTransaction(OutgoingTransactionRqstInfo req) { String cer = System.Text.ASCIIEncoding.ASCII.GetString(HttpContext.Current.Request.ClientCertificate.Certificate); Int32 messageID = (req!=null)?req.messageID:0; String filename = String.Format(ConfigurationManager.AppSettings["fileout"], DateTime.Now, messageID); using (StreamWriter stream = new StreamWriter(filename, true)) { stream.WriteLine(cer); stream.Flush(); stream.Close(); } }
J'ai configuré mon serveur IIS7.5 pour gérer l'authentification cliente par certificat.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(SSLCertificate.ValidateRemoteCertificate); localhost.Service service = new localhost.Service(); service.ClientCertificates.Clear(); String cer = "MIIC+TCCA......uw1jfIJJfXw"; byte[] cerClient = new System.Text.ASCIIEncoding().GetBytes(cer); X509Certificate cerX509 = new X509Certificate(cerClient); service.ClientCertificates.Add(cerX509); localhost.OutgoingTransactionRqstInfo rqs = new localhost.OutgoingTransactionRqstInfo(); service.outgoingTransaction(rqs);
cf . http://www.developpez.net/forums/d11...t/#post6346950
Merci de votre retour.
Partager