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

C# Discussion :

WCF, Réponse du serveur [Débutant]


Sujet :

C#

  1. #1
    Membre habitué Avatar de DeVaK
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2013
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Janvier 2013
    Messages : 45
    Points : 140
    Points
    140
    Par défaut WCF, Réponse du serveur
    Bonjour,

    J'essaye de suivre un petit tuto trouvé sur un autre site.

    J'en suis au codage du serveur dans une application console.
    J'imagine que j'ai fais un peu n'importe quoi parce que du coup l'application plante au démarrage quand il arrive à la ligne 40 en me soulevant l'exception "InvalidOperationException". Il dit qu'il ne trouve pas le fichier de configuration de l'application, qui y est pourtant sous le nom "app.config".

    Je vous donne le code de mon serveur (vous inquiétez pas, c'est pas long) :

    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
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Contrat;
    using System.ServiceModel;
     
    namespace ConsoleApplication1
    {
        [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant, InstanceContextMode = InstanceContextMode.PerSession)]
        public class FxComServer : Iserver
        {
            private string login;
            private Iclient client;
     
            public bool Login(string user, string password)
            {
                login = user;
                client = OperationContext.Current.GetCallbackChannel<Iclient>();
                return true;
            }
     
            public bool Say(string text)
            {
                client.ReceiveMessage(login + " said " + text);
                return true;
            }
     
     
            internal static class Host
            {
                internal static ServiceHost myServiceHost = null;
     
                internal static void StartService()
                {
                    //Instantiate new ServiceHost
                    myServiceHost = new ServiceHost(typeof(ConsoleApplication1.FxComServer));
                    //Open myServiceHost
                    myServiceHost.Open();
                }
     
                internal static void StopService()
                {
                    //Call StopService from your shutdown logic (i.e. dispose method)
                    if (myServiceHost.State != CommunicationState.Closed)
                        myServiceHost.Close();
                }
     
                static void Main(string[] args)
                {
                    StartService();
     
     
                    // On attend les connections
                    Console.WriteLine("Server ready");
                    Console.ReadLine();
     
                    StopService();
                }
            }
        }
     
    }
    Merci de votre aide ^^'.

  2. #2
    Membre expert
    Avatar de GuruuMeditation
    Homme Profil pro
    .Net Architect
    Inscrit en
    Octobre 2010
    Messages
    1 705
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : .Net Architect
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 705
    Points : 3 568
    Points
    3 568
    Par défaut
    Tu as bien une configuration WCF (endpoint,etc) dans ton app.config?
    Microsoft MVP : Windows Platform

    MCPD - Windows Phone Developer
    MCPD - Windows Developer 4

    http://www.guruumeditation.net

    “If debugging is the process of removing bugs, then programming must be the process of putting them in.”
    (Edsger W. Dijkstra)

  3. #3
    Membre habitué Avatar de DeVaK
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2013
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Janvier 2013
    Messages : 45
    Points : 140
    Points
    140
    Par défaut
    Oui. En fait j'ai bêtement fait un copier / coller de ce qu'il y a marqué sur le tuto :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.serviceModel>
        <services>
          <service name="FxCommunicatorServer.FxComServer">
            <endpoint contract="FxCommunicatorService.IServer" binding="netTcpBinding" address="net.tcp://localhost:1303"/>
            <endpoint contract="FxCommunicatorService.IServer" binding="wsDualHttpBinding" address="http://localhost:80"/>
          </service>
        </services>
      </system.serviceModel>
    </configuration>
    En créant un fichier xml sous visual studio, en le nommant "app.config" et en le remplissant d'un simple c/c. Peut-être qu'il faut le lié quelque part et que le projet ne le récupère pas seul? Honnêtement j'ai jamais utilisé app.config.

    En cours j'ai fais la définition du endpoint et du service directement dans le code donc je comprend pas trop comment il fait le lien avec le fichier xml.

    D'ailleurs en cours j'ai fais la communication que dans un sens, d'où ma recherche pour la communication dans l'autre sens histoire de pouvoir développer un Huit Américain pour un projet client / serveur.


    EDIT : AH DAMN!!! Je suis un idiot. C'est pas le bon projet de marqué sur le app.config pour le service. Je vous dis si c'est ça.

    EDIT 2 : Bon j'ai repris mon fichier de conf en mettant les valeurs correspondant réellement à mes différents projet (on est pas frais à 1h40 du matin, c'était évident :/ ). Mais ça ne fonctionne quand même pas. C'est pas grand chose mais voilà ce qu'il est devenu :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.serviceModel>
        <services>
          <service name="ConoleApplication1.FxComServer">
            <endpoint contract="Contrat.Iserver" binding="netTcpBinding" address="net.tcp://localhost:1303"/>
            <endpoint contract="Contrat.Iserver" binding="wsDualHttpBinding" address="http://localhost:80"/>
          </service>
        </services>
      </system.serviceModel>
    </configuration>

  4. #4
    Membre expert
    Avatar de GuruuMeditation
    Homme Profil pro
    .Net Architect
    Inscrit en
    Octobre 2010
    Messages
    1 705
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : .Net Architect
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 705
    Points : 3 568
    Points
    3 568
    Par défaut
    Dans servicename, il manque un s à ConsoleApplication1. Tu as écrit ConsoleApplication1.
    Microsoft MVP : Windows Platform

    MCPD - Windows Phone Developer
    MCPD - Windows Developer 4

    http://www.guruumeditation.net

    “If debugging is the process of removing bugs, then programming must be the process of putting them in.”
    (Edsger W. Dijkstra)

  5. #5
    Membre habitué Avatar de DeVaK
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Janvier 2013
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Janvier 2013
    Messages : 45
    Points : 140
    Points
    140
    Par défaut
    ... J'ai honte.

    Bref merci d'y avoir jeter un oeil, ça fonctionne ^^.

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

Discussions similaires

  1. Réponses: 5
    Dernier message: 18/11/2009, 17h17
  2. [WCF] CommunicationException entre serveur et BD
    Par kazoumoulox dans le forum Windows Communication Foundation
    Réponses: 5
    Dernier message: 08/05/2008, 11h42
  3. [AJAX] Redirection après réponse du serveur
    Par acidline dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 13/08/2007, 14h51
  4. Réponses: 7
    Dernier message: 25/08/2006, 14h15

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