IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Communication Foundation .NET Discussion :

Problème de configuration WCF REST JSON [Débutant]


Sujet :

Windows Communication Foundation .NET

  1. #1
    Membre éprouvé Avatar de kheironn
    Homme Profil pro
    Chef de projets technique C# / MVC / .Net
    Inscrit en
    Février 2007
    Messages
    822
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Chef de projets technique C# / MVC / .Net
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2007
    Messages : 822
    Points : 1 108
    Points
    1 108
    Par défaut Problème de configuration WCF REST JSON
    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) :
    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 contrat :
    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);
        }
    }
    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 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" };
            }
        }
    }
    tout ça, c'est pour démarrer, une fois compris comment ça marche, je pourrais faire un vrai truc.
    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.
    En informatique, le problème se situe toujours entre le clavier et l'écran !
    Il y a deux chemins entre le clavier et l'écran : Par l'UC et par l'utilisateur.

  2. #2
    Membre confirmé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2011
    Messages
    269
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2011
    Messages : 269
    Points : 460
    Points
    460
    Par défaut
    Bonjour,

    La première configuration WCF peut en effet être difficile.
    Dans les choses qui peuvent perturbé : remplir un attribut avec rien, soit il est renseigné, soit il n'est pas présent sur le noeud.

    Voici les changement que j'appliquerai sur ta config
    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
    <system.serviceModel>
        <services>
          <service name="WcfService2.Service1">
            <endpoint behaviorConfiguration="RestEndPointBehavior"
              binding="webHttpBinding" name="EndPointRest"
              bindingNamespace="http://localhost/WcfService2" contract="WcfService2.IService1" />
            <endpoint address="mex" binding="mexHttpBinding"
              bindingNamespace="http://localhost/WcfService2"
              contract="IMetadataExchange" />
          </service>
        </services>
        <behaviors>
          <endpointBehaviors>
            <behavior name="RestEndPointBehavior">
              <webHttp />
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
              <dataContractSerializer />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
    J'ai enlevé address="rest" car, tu ne semble pas accéder a ton WebService via cette url.
    De mémoire l'url d'accès avec une adresse définit serait http://localhost/WcfService2/rest/

    Sinon l'attribut contract des endpoint utilise toujours une interface tagué avec ServiceContract.

    Enfin petite question, comment initialises-tu ton service? IIS, un hosteur personnalisé?

  3. #3
    Membre éprouvé Avatar de kheironn
    Homme Profil pro
    Chef de projets technique C# / MVC / .Net
    Inscrit en
    Février 2007
    Messages
    822
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Chef de projets technique C# / MVC / .Net
    Secteur : Conseil

    Informations forums :
    Inscription : Février 2007
    Messages : 822
    Points : 1 108
    Points
    1 108
    Par défaut
    Merci pour ces infos. Entre-temps un collègue qui maitrise la techno est rentré de vacances et m'a filer un coup de main.

    Il me reste à comprendre pourquoi, lorsque je remplace localhost par mon ip, ça ne marche pas et pourquoi j'ai une erreur 500 (telerik fiddler) sur une méthode.

    sinon, j'utilisai le serveur intégré... Pour la suite, je vais utiliser un IIS 7 sur ma machine.
    En informatique, le problème se situe toujours entre le clavier et l'écran !
    Il y a deux chemins entre le clavier et l'écran : Par l'UC et par l'utilisateur.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. WCF Rest JSon
    Par cyril dans le forum Services Web
    Réponses: 1
    Dernier message: 10/06/2013, 18h05
  2. Sencha touche consommer une service WCF Rest JSON
    Par aymen8219 dans le forum Ext JS / Sencha
    Réponses: 1
    Dernier message: 23/02/2013, 20h31
  3. Service Web WCF REST JSON et firefox
    Par FraktaL dans le forum Services Web
    Réponses: 8
    Dernier message: 13/02/2013, 17h51
  4. [EJB / REST / JSON / JQuery] Problème pour faire un POST
    Par saveriu dans le forum Services Web
    Réponses: 1
    Dernier message: 19/04/2012, 11h08
  5. Problème d'encodage fichier JSON avec WCF REST Service
    Par Spikuria dans le forum Services Web
    Réponses: 0
    Dernier message: 09/03/2012, 10h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo