Bonjour,
Je vous écris car j'ai un problème pour la consommation d'un Web Service en C# mode console.
J'intègre l'appel au service via l'ajout d'un "Service Reference" grâce au WSDL.
Le service est disponible au travers d'un transport par certificat.
Avec le binding suivant
Code XAML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 <bindings> <wsHttpBinding> <binding name="***"> <security mode="Transport"> <transport clientCredentialType="None" /> </security> </binding> </wsHttpBinding> </bindings>
Je trouve, j'ajoute le certificat au context et j'appelle la méthode sendReport :
Mon problème est que mon appel vers le service me retourne une erreur : "Bad Request".
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 ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; string certThumbPrint = "***"; X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser); certStore.Open(OpenFlags.ReadOnly); X509Certificate2Collection certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, certThumbPrint, false); certStore.Close(); if (0 == certCollection.Count) { Console.WriteLine("Error: No certificate found containing thumbprint "); } X509Certificate2Enumerator enumerator = certCollection.GetEnumerator(); X509Certificate2 cert = null; while (enumerator.MoveNext()) { cert = enumerator.Current; } context = new ***Service.***Client(); context.ClientCredentials.ClientCertificate.Certificate = cert; //Appel au service context.sendReport(rt, out result);
Après investigation avec le fournisseur du service, c'est car mon XML envoyé n'est pas signé.
A titre d'exemple, j'ai reçu ce <soapenv:header>, et mon appel doit correspondre à ce design.
Code XAML : 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 <soapenv:Header> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <!-- X509 Certificate used for the signatures --> <wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="***">***</wsse:BinarySecurityToken> <!-- Timestamp with a Created element and an Expires element --> <wsu:Timestamp wsu:Id="TS-F395***CD41FB929"> <wsu:Created>2019-04-03T09:08:14Z</wsu:Created> <wsu:Expires>2019-04-03T09:13:14Z</wsu:Expires> </wsu:Timestamp> <!-- Signature part --> <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> <SignedInfo> <!-- Exclusive XML Canonicalization for the signature --> <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> <!-- SignatureMethod Algorithm : rsa-sha256 --> <SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/> <!-- Timestamp part --> <!-- The URI attribute corresponds to the wsu:Id of the Timestamp --> <Reference URI="#TS-F395***CD41FB929"> <Transforms> <!-- Exclusive XML Canonicalization --> <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> </Transforms> <!-- Algorithm to use for the signature of the Timestamp : SHA256 --> <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> <DigestValue>HEddgN6c/Ervwn***RQYa00NdY=</DigestValue> </Reference> <!-- Body part --> <!-- The URI attribute corresponds to the wsu:Id of the Body --> <Reference URI="#BODY-2FB6***62B8FD846"> <Transforms> <!-- Exclusive XML Canonicalization --> <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> </Transforms> <!-- Algorithm to use for the signature of the Body : SHA256 --> <DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/> <DigestValue>rVUZ+xKkdyJLQz***Kkyf+ckcckUNguc=</DigestValue> </Reference> </SignedInfo> <!-- The signature --> <SignatureValue>aw7rvvLEXZ***v8HwU1aeo4=</SignatureValue> <!-- Where the certificate is located --> <KeyInfo Id="KEYI***65872F4"> <wsse:SecurityTokenReference wsu:Id="STR-FB2D5***3EF" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <!-- The ID of the BinarySecurityToken element --> <wsse:Reference URI="#X509-459F***1ACE" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/> </wsse:SecurityTokenReference> </KeyInfo> </Signature> </wsse:Security> </soapenv:Header>
Est-ce qu'il existe un composant/référence/librairie à ajouter au projet qui génère automatiquement ce type de signature?
Sinon, est-ce que quelqu'un a déjà intégré ce genre de signature, est-ce qu'il y a un tutoriel?
Si possible en continuant d'utiliser l'appel à la méthode intégrée sans ré-écrire un XML "custom".
Désolé si la question a déjà été posée, je n'ai pas trouvé de sujet équivalent.
Merci pour votre aide.
Partager