Bonjour tout le monde, j'ai un problème pour configurer l'utilisation d'un service WCF.
Ptit point sur mon archi:
J'ai créé un service WCF dans une assembly à part:
Le ServiceContract:
Le DataContract:Code:
1
2
3
4
5
6
7
8
9
10
11 using BlotterLight.ServiceDataContract; namespace BlotterLight.ServiceInterface { // Defines IStudentService here [ServiceContract(Namespace = "BlotterLight.ServiceInterface")] public interface IBlotterService { ... } }
L'implémentation du service:Code:
1
2
3
4
5
6
7
8 namespace BlotterLight.ServiceDataContract { [DataContract] public class RfqCdDpEur { ... } }
Le but du jeu est maintenant de hoster et de consommer ce service dans une appli web.Code:
1
2
3
4
5
6
7
8
9
10
11
12 using BlotterLight.ServiceDataContract; using BlotterLight.ServiceInterface; namespace BlotterLight.Service { // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in App.config. [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] public class BlotterService : IBlotterService { } }
Dans mon appli web, j'ai créé un dossier /WebServices et j'ai ajouté un fichier Service.svc qui host mon service:
Mon web.config contient alors:Code:<%@ ServiceHost Language="C#" Debug="true" Service="BlotterLight.Service.BlotterService" %>
Je consomme ce service en AJAX dans une page et tout fonctionne nickel.Code:
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 <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="BlotterServiceBehavior"> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="true" /> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="BlotterLightWeb.WebServices.ServiceAspNetAjaxBehavior"> <enableWebScript /> </behavior> </endpointBehaviors> </behaviors> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> <services> <service name="BlotterLight.Service.BlotterService" behaviorConfiguration="BlotterServiceBehavior"> <endpoint address="" behaviorConfiguration="BlotterLightWeb.WebServices.ServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="BlotterLight.ServiceInterface.IBlotterService" /> <!--<endpoint address="" binding="wsHttpBinding" contract="BlotterLight.ServiceInterface.IBlotterService"> </endpoint>--> </service> </services> </system.serviceModel>
Maintenant, je souhaite consommer ce service dans une autre page mais en code behind cette fois-ci.
Il va donc falloir que je crée un client.
Pour ça, clic droit -> add service reference. Je clique sur Discover et je choisi WebServices/Service.svc.
Mon fichier web.config est alors enrichi avec:
Quand j'exécute ma page, j'obtiens:Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 <bindings> <customBinding> <binding name="WebHttpBinding_IBlotterService" > <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Soap12" writeEncoding="utf-8"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> </textMessageEncoding> </binding> </customBinding> </bindings> <client> <endpoint binding="customBinding" bindingConfiguration="WebHttpBinding_IBlotterService" contract="BlotterLight.Service.IBlotterService" name="WebHttpBinding_IBlotterService" /> </client>
The CustomBinding on the ServiceEndpoint with contract 'IBlotterService' lacks a TransportBindingElement. Every binding must have at least one binding element that derives from TransportBindingElement.
Soit, j'ajoute <httpTransport/> à mon binding.
Maintenant, j'obtiens:
The Address property on ChannelFactory.Endpoint was null. The ChannelFactory's Endpoint must have a valid Address specified.
1- Pourquoi VS2008 n'a pas automatiquement généré la propriété Address?
2- Que mettre?
J'ai essayé avec address="/WebServices/Service.svc". J'obtiens The given URI must be absolute.
Nom du paramètre : uri
J'ai essayé avec http://localhost:4042/WebServices/Service.svc. J'obtiens Le serveur distant a retourné une erreur : (404) Introuvable.
Alors que si je tape cette url dans IE, je vois bien mon service.
Voilà mon code behind au cas où:
Code:
1
2
3
4
5 var client = new BlotterServiceClient(); client.Open(); var rfq = client.Mafonction(); // ToDo client.Close();
Que faire maintenant?
Merci
edit: désolé pour le pavé :aie: