Bonjour,
Je dois développer une petite application offrant des WS en WCF retournant du json (et l'utilisant en paramètre d'entrée).
Problème : je ne suis pas du tout familiarisé avec WCF et encore moins quand il faut faire du REST. en SOAP, je n'ai aucun problème, ça marche tout seul...
en C# 4.0
voici ma config (foireuse) :mon contrat :
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 <?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <services> <service name="WcfService2.Service1"> <endpoint address="rest" behaviorConfiguration="RestEndPointBehavior" binding="webHttpBinding" bindingConfiguration="" name="EndPointRest" bindingNamespace="http://localhost/WcfService2" contract="WcfService2.Service1" /> <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" name="EndPointMex" bindingNamespace="http://localhost/WcfService2" contract="IMetadataExchange" /> </service> </services> <behaviors> <endpointBehaviors> <behavior name="RestEndPointBehavior"> <webHttp /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name=""> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> <dataContractSerializer /> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> <!-- To browse web app root directory during debugging, set the value below to true. Set to false before deployment to avoid disclosing web app folder information. --> <directoryBrowse enabled="true"/> </system.webServer> </configuration>mon service :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 namespace WcfService2 { // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together. [ServiceContract] public interface IService1 { [OperationContract] [WebInvoke(BodyStyle=WebMessageBodyStyle.Wrapped,Method="POST",RequestFormat=WebMessageFormat.Json,ResponseFormat=WebMessageFormat.Json,UriTemplate="GetData")] Worker GetData(string value); } }tout ça, c'est pour démarrer, une fois compris comment ça marche, je pourrais faire un vrai truc.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 namespace WcfService2 { // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together. // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging. public class Service1 : IService1 { public Worker GetData(string value) { return new Worker() { Name = "Smith", Firstname = "John" }; } } }
Mon problème actuel est que je n'arrive à configurer le bazar... pour le moment, je me fais jeter pour une histoire de métadonnées non accessibles.
Après, on verra si ça me sort bien quelque chose, sur mon essaie précédant, il me mettait cette erreur là :"The Address property on ChannelFactory.Endpoint was null. The ChannelFactory's Endpoint must have a valid Address specified."
nouveaux projet, nouvelle config et j'ai ça : "Error: Cannot obtain Metadata from http://localhost/WcfService2/Service1.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address."
Si vous pouvez m'aider pour ces deux erreur, ça m'arrangerait bien.
merci à vous.
Partager