Bonjour,
Désolée de créer un énième topic (promis, c'est le dernier) mais j'ai encore un problème qui me géne.
Comme je l'ai évoqué dans mon précédent topic, je souhaite créer un Service WCF qui est exposé via basicHttpBinding en https. Au niveau de l'authentification, j'utilise UserNamePasswordValidator. Tout cela fonctionne parfaitement.
Désormais, je souhaiterais exposer mon service sur un second point de terminaison en WebHttpBinding. Après avoir trouvé quelques tutoriaux sur le net, j'ai commencé la modification de mon Web.Config.
J'ai ajouté un EndPoints :
Un binding :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 <endpoint address="SOAP" binding="basicHttpBinding" contract="MonService.ServiceContract.IMonServiceWCF" bindingConfiguration="soapBinding" /> <endpoint address="REST" binding="webHttpBinding" contract="MonService.ServiceContract.IMonServiceWCF" behaviorConfiguration="PoxBehavior" bindingConfiguration="webBinding" />
Et un Endpoint Behavior :
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 <bindings> <basicHttpBinding> <binding name="soapBinding" > <security mode="TransportWithMessageCredential" > <transport clientCredentialType="Basic" /> </security> </binding> </basicHttpBinding> <webHttpBinding> <binding name="webBinding"> <security mode="Transport" > </security> </binding> </webHttpBinding> </bindings>
Au final, je voudrais proposer le service en SOAP, en Pox et en JSON. Pour l'instant, on va faire SOAP (déjà fais) et Pox.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5<endpointBehaviors> <behavior name="PoxBehavior"> <webHttp /> </behavior> </endpointBehaviors>
A ce stade, mon Web.Config ressemble à ça :
Ps : Si vous voyez un truc pas bon dans mon fichier de configuration, merci de me le dire.
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
61
62
63
64
65
66
67
68
69
70
71
72 <?xml version="1.0"?> <configuration> <system.web> <customErrors mode="Off"/> </system.web> <connectionStrings> <add name="MesEntities" connectionString="ma chaine de connexion" /> </connectionStrings> <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> <services> <service name="MonService.WCFService.MonServiceWCF" behaviorConfiguration="MetadataWSDL"> <host> <baseAddresses> <add baseAddress="https://localhost"/> </baseAddresses> </host> <endpoint address="SOAP" binding="basicHttpBinding" contract="MonService.ServiceContract.IMonServiceWCF" bindingConfiguration="soapBinding" /> <endpoint address="REST" binding="webHttpBinding" contract="MonService.ServiceContract.IMonServiceWCF" behaviorConfiguration="PoxBehavior" bindingConfiguration="webBinding" /> </service> </services> <bindings> <basicHttpBinding> <binding name="soapBinding" > <security mode="TransportWithMessageCredential" > <transport clientCredentialType="Basic" /> </security> </binding> </basicHttpBinding> <webHttpBinding> <binding name="webBinding"> <security mode="Transport" > </security> </binding> </webHttpBinding> </bindings> <behaviors> <endpointBehaviors> <behavior name="PoxBehavior"> <webHttp /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="MetadataWSDL"> <serviceCredentials> <userNameAuthentication customUserNamePasswordValidatorType="MonService.WCFService.CustomUserNameValidator, MonService.WCFService" userNamePasswordValidationMode="Custom" /> </serviceCredentials> <serviceMetadata httpsGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true" /> <dataContractSerializer maxItemsInObjectGraph="6553600"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration>
J'ai créé une nouvelle méthode sur mon service :
Interface :
Implémentation :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 [WebGet(UriTemplate = "date/{year}/{month}/{day}", ResponseFormat = WebMessageFormat.Xml)] [OperationContract()] string GetDate(string day, string month, string year);
Avec mon navigateur, si je fais :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 public string GetDate(string day, string month, string year) { return new DateTime(Convert.ToInt32(year), Convert.ToInt32(month), Convert.ToInt32(day)).ToString("dddd, MMMM dd, yyyy"); }
J'ai bien ceci qui s'affiche :
Code : Sélectionner tout - Visualiser dans une fenêtre à part https://monserveur/MonServiceWCF.svc/REST/date/1995/10/10
Ca semble fonctionner donc.
Code : Sélectionner tout - Visualiser dans une fenêtre à part <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">mardi, octobre 10, 1995</string>
Le problème vient de mon client WPF. Désormais, j'ai un avertissement qui apparait :
Et si je tente quand meme de lancer l'application, j'intercépte une exception :Custom tool warning: The following Policy Assertions were not Imported:
XPath://wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='WebHttpBinding_IMonServiceWCF']
Assertions:
<sp:HttpsToken xmlns:sp='http://schemas.xmlsoap.org/ws/2005/07/securitypolicy'>..</sp:HttpsToken>
C:\MonServiceClientWPF\Service References\MonServiceReference\Reference.svcmap
D'aprés ce que j'en comprends, il est un peu perdu à cause des deux endpoints et il faut lui indiquer lequel on veut utiliser. Bien ça ? Le problème, c'est que je vois pas comment faire ça en C#.Une section de configuration du point de terminaison du contrat "MonServiceReference.IMonServiceWCF" n'a pas pu être chargée car plusieurs configurations de point de terminaison pour ce contract ont été détectées. Indiquez la section de configuration du point de terminaison préférée par son nom.
Je précise que pour utiliser mon service dans mon application WPF, j'ai utilisé le générateur auto de Visual Studio en faisant "Add Service Reference" dans le projet.
Merci encore pour votre aide.
Partager