Bonjour actuellement en plein web service, j'essaye de crée un web service sécurisé en mode securité "Message" et le Message ClientCredentielType "UserName".
J'ai bien crée mon service et le certificat associé et mon service fonctionne.
Le soucie est quand j'appelle ma méthode de mon service dans mon client j'ai l'erreur :
"Une faute non sécurisée ou incorrectement sécurisée a été reçue de l'autre partie. Voir le FaultException interne pour le code et les détails de la faute."
Dans le détail de l'erreur dans innerException il y a écris : "Au moins un jeton de sécurité du message n'a pas pu être validé."
Merci d'avance pour tout aide apportée.
Je vous passe mes codes pour une vision global.
Mon webConfig Service:
Mon AppConfigClient:
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 <?xml version="1.0"?> <configuration> <system.web> <!--<menbership> <providers> <add name="MyMenbershipProvider" type="Service.MyCustomUsernamePasswordValidator, Service"/> </providers> </menbership>--> <compilation debug="true" targetFramework="4.0"/> <authentication mode="Windows"/> <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/> </system.web> <system.webServer> <directoryBrowse enabled="true"/> </system.webServer> <system.serviceModel> <services> <service name="Service.EchoClaims" behaviorConfiguration="echoClaimsBehavior"> <endpoint address="EchoClaims" contract="Service.IEchoClaims" binding="wsHttpBinding" bindingConfiguration="echoClaimsBinding"/> </service> </services> <bindings> <wsHttpBinding> <binding name="echoClaimsBinding"> <!--<security mode="Message"> <transport clientCredentialType="Basic" proxyCredentialType="Basic" /> <message clientCredentialType="UserName"/> </security>--> <security mode="Message"> <message clientCredentialType="UserName" negotiateServiceCredential="true"/> </security> </binding> </wsHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="echoClaimsBehavior"> <serviceCredentials> <serviceCertificate findValue="CN=MySuperCe" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectDistinguishedName"/> <userNameAuthentication userNamePasswordValidationMode="Windows"></userNameAuthentication> <clientCertificate> <!--<authentication certificateValidationMode="Custom" customCertificateValidatorType="Common.MyCertificateValidator, Common"/>--> </clientCertificate> </serviceCredentials> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration>
Et mon Programme client
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
43
44
45 <?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <system.serviceModel> <client> <endpoint address="http://localhost:54059/EchoClaims.svc/EchoClaims" binding="wsHttpBinding" bindingConfiguration="echoClaimsBinding" contract="ServiceReference1.IEchoClaims" name="WSHttpBinding_IEchoClaims" behaviorConfiguration="echoClaimsBehavior"> <identity> <dns value ="MySuperCe" /> </identity> </endpoint> </client> <bindings> <wsHttpBinding> <binding name="echoClaimsBinding"> <security mode="Message"> <message clientCredentialType="UserName" negotiateServiceCredential="true"/> </security> </binding> </wsHttpBinding> </bindings> <behaviors> <endpointBehaviors> <behavior name="echoClaimsBehavior"> <clientCredentials> <serviceCertificate> <authentication certificateValidationMode="None" revocationMode="NoCheck"/> </serviceCertificate> </clientCredentials> </behavior> </endpointBehaviors> </behaviors> </system.serviceModel> </configuration>
Et pour finir ma classe Du serveur
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 EchoClaimsClient client = new EchoClaimsClient(); client.ClientCredentials.UserName.UserName = "joe"; client.ClientCredentials.UserName.Password = "bar"; string[] claims = client.Echo(); foreach (string claim in claims) { Console.WriteLine(claim); }
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 public List<string> Echo() { List<string> claims = new List<string>(); foreach (ClaimSet set in OperationContext.Current.ServiceSecurityContext.AuthorizationContext .ClaimSets) { foreach (Claim claim in set) { claims.Add(string.Format("{0} - {1} - {2}", claim.ClaimType, claim.Resource.ToString(), claim.Right)); } } return claims; }
Partager