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 Phone .NET Discussion :

Récuperation de resultat de la requete select d'une bdd mysql via un webservice avec windows phone c# [Windows Phone 7]


Sujet :

Windows Phone .NET

  1. #1
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 20
    Points : 11
    Points
    11
    Par défaut Récuperation de resultat de la requete select d'une bdd mysql via un webservice avec windows phone c#
    Bonsoir,
    Alors là je cherche dans mon app mobile réalisée sous windows phone avec c# , récuperer le resultat de ma requete select . alors j'ai créé un webservice par WCF et voilà on detail ce que j'ai fais:

    Dans le fichier IService.cs je défini ma fonction "SelectSociete()" de selection :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    [OperationContract]
            string SelectSociete();

    et puis dans le IService.svc.cs j'écrit le code de ma fonction comme suit:

    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
     
      public string SelectSociete()
            {
                //Object MysqlConnection
                MySqlConnection connection;
                string server;
                string database;
                string uid;
                string password;
                //Paramétre de la base
                server = "localhost";
                database = "gare_tetouan";
                uid = "root";
                password = "";
                //String
                string connectionString;
                connectionString = "SERVER=" + server + ";" + "DATABASE=" +
                database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
                connection = new MySqlConnection(connectionString);
                //Ouverture de la connection
                connection.Open();
                //Préparation de la requete
                string query = "SELECT nom_societe FROM `societe`";
                MySqlCommand cmd = new MySqlCommand(query, connection);
                //Exécution de la requette
                String nom=(String)cmd.ExecuteScalar();
                //fermeture de la connection
                connection.Close();
                //TEST de retour
                return nom;
            }
    ensuite je vais remplire un combobox (ou une ListPicker)de ce qu'on va recuperer comme resultat de notre requete select, dans ma page accueil.xaml.cs où j'aurai mon combo et dans l'evenement du load de l'application

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
     private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
            {
               ServiceConsum.Service1Client client = new ServiceConsum.Service1Client();
                ComboBox1.Items.Add(client.SelectSocieteAsync());
     
            }



    Surement j'ai des erreurs
    mais lesquel et que dois je faire

    SOS tout aide sera utile : doc ou guide ou tutorial ou idée tout peut me servire

    et Merci d'avance

  2. #2
    Membre actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2008
    Messages
    242
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Conseil

    Informations forums :
    Inscription : Août 2008
    Messages : 242
    Points : 296
    Points
    296
    Par défaut
    Bonjour,

    Premièrement,
    Lors d'appelle à une base de donnée/service wcf (pour vous, les deux), on utilise toujours ce format:
    1. Try
    2. Open connexion
    3. Execute Query
    4. Catch Exception
    5. Finally close connexion


    Deuxièmement, Est-ce que "client.SelectSocieteAsync()" renvoit bien quelque chose?

    Troisièmement, utilisez le MvvM car l'ajout dans l'UI est asynchrone.

    Un petit tuto ici

    Cordialement,

  3. #3
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 20
    Points : 11
    Points
    11
    Par défaut
    Merci Beaucoup pour votre réponse
    Mais dans mon cas ma base de données est une base mysql donc je ne sais pas si ce tuto que vous m'avez envoyé marchera pour mon cas aussi, sinon voilà le tuto sur lequel je me suis basée :
    http://elmagnif.wordpress.com/2012/0...windows-phone/

    pour ma fonction je l'avais changé pour remplir une list par ce que je récupère de ma base et voilà mon code :
    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
     
    public List<string> SelectSociete(List<string> nom)
    {
     
    nom = new List<string>();
    //Object MysqlConnection
    MySqlConnection connection;
    string server;
    string database;
    string uid;
    string password;
     
    server = "localhost";
    database = "gare_tetouan";
    uid = "root";
    password = "";
     
    string connectionString;
    connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
    connection = new MySqlConnection(connectionString);
     
    connection.Open();
     
    string query = "SELECT nom_societe FROM 'societe'";
    MySqlCommand cmd = new MySqlCommand(query, connection);
    cmd.ExecuteNonQuery();
    MySqlDataReader reader = cmd.ExecuteReader();
     
    while (reader.Read()) 
    {
    nom.Add(reader["nom_societe"].ToString());
     
    }
     
    reader.Close();
    connection.Close();
     
    return nom;
     
    }
    cette fonction retourne bien une liste de mes enregistrements de BDD , ça je le sais par le teste de client du webservice

    et puis dans mon app mobile dans l'action du load je passe une list comme parametre de ma fonction pour qu'elle sera remplis par ce que ma fonction retourn, pour remplir par la suite une listpicker par cette list , voilà mon code:

    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
    private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
    {
    try
    {
     
    ServiceConsum.Service1Client client = new ServiceConsum.Service1Client();
    client.SelectSocieteAsync(list);
    this.listpicker.ItemsSource = list;
     
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    }
    }
    Mon code me semble parfait et correcte !!! j'ai dis bien me semble
    Mais ça ne marche pas comme il faut et ma liste ne se rempli pas !!!
    j'ignore pourquoi et comment faire ???

  4. #4
    Membre habitué
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2013
    Messages : 7
    Points : 139
    Points
    139
    Par défaut
    Salut,

    Ton code ma l'air correct cependant tu ne récupère pas les données de la bonne façon.

    il faut que tu implémente l'événement " client.SelectSocieteCompleted " dans ta classe Service1Client puisque le traitement ce fait de façon asynchrone.

    Voici un exemple :
    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
     
    public void LoadArticles(Guid idTitle)
            {
                ConstitutionClient client = new ConstitutionService.ConstitutionClient();
                client.GetArticlesAsync(idTitle);
                client.GetArticlesCompleted += new EventHandler<GetArticlesCompletedEventArgs>(client_GetArticlesCompleted);
                client.CloseAsync();
            }
     
            void client_GetArticlesCompleted(object sender, GetArticlesCompletedEventArgs e)
            {
                if (e.Error == null)
                {
                    if (e.Result != null)
                    {
                        OnDownloadFinished();
                        Articles = e.Result;
                        ArticlesDownloaded = true;
                    }
                }
            }

  5. #5
    Membre actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2008
    Messages
    242
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Conseil

    Informations forums :
    Inscription : Août 2008
    Messages : 242
    Points : 296
    Points
    296
    Par défaut
    Pourquoi codez-vous dans la méthode "PhoneApplicationPage_Loaded" et pas dans le code behind d'une page?

  6. #6
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 20
    Points : 11
    Points
    11
    Par défaut
    Merci Younes en fait oui j'ai deja utiliser l'evenement completed et pourtant ça marche pas, de toute façon cet evenement permet de faire un traitement après avoir executé le service c'est tout donc en tt cas ça n'a pas d'influance sur mon code je crois

    Mais soit que j l'utilise ou pas ca ne marche paaaaaas

  7. #7
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 20
    Points : 11
    Points
    11
    Par défaut
    Maf77 merci pour ta reponse en tt cas soit dans le load ou le constructeur ou dans une bouton mem (juste pour teste) ça doit marché alors que Rien ne marche !! j risque de perdre ma tete mon code me semble correeecte Mais qu'il ne marche pas

  8. #8
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 20
    Points : 11
    Points
    11
    Par défaut
    J'ai lu dans un forum qu'on doit changer la configuration des collections du service coté client : Configure Service Reference et modifie Collection Type en List.
    Mais pourtant ça marche pas
    Donc ??

  9. #9
    Membre habitué
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2013
    Messages : 7
    Points : 139
    Points
    139
    Par défaut
    Non ne modifie pas les types de collection en List laisse les à ObservableCollection.


    Montre nous à nouveau ton code pour voir.

    Sinon regarde dans ma chaîne Youtube Le tuto consommation service web, ça pourra t'aider si tu as zapper un truc.

  10. #10
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 20
    Points : 11
    Points
    11
    Par défaut
    d'acc merciiiiiiiii . alors voilà mon code :
    dans Iservice1.cs : déclaration de ma fonction
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     [OperationContract]
            List<string> SelectSociete(List<string> nom);
    pour ma fonction dans service.svc.cs:

    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
     public List<string> SelectSociete(List<string> nom)
            {
                //test = "11";
                nom = new List<string>();
                //Object MysqlConnection
                MySqlConnection connection;
                string server;  
                string database;       
                string uid;   
                string password;
     
                server = "localhost";
                database = "gare_tetouan";
                uid = "root";
                password = "";
     
                string connectionString;
                connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
                connection = new MySqlConnection(connectionString);
     
                connection.Open();
     
                string query = "SELECT nom_societe FROM `societe`"; 
                MySqlCommand cmd = new MySqlCommand(query, connection);
                cmd.ExecuteNonQuery();
                MySqlDataReader reader = cmd.ExecuteReader();
     
                  while (reader.Read()) 
                    {
                        nom.Add(reader["nom_societe"].ToString());
     
                      }
     
                reader.Close();           
                connection.Close();
     
                return nom;
     
     
            }
    et dans le code de mon app mobile voilà :
    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
     
    private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
            {
     
                try
                {
     
                    ServiceConsum.Service1Client client = new ServiceConsum.Service1Client();
                    client.SelectSocieteAsync(list);
                    this.listpicker.ItemsSource = list;
                    client.SelectSocieteCompleted += new EventHandler<SelectSocieteCompletedEventArgs>(client1_SelectSocieteCompleted);
     
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
     
            private void client1_SelectSocieteCompleted(object obj, ServiceConsum.SelectSocieteCompletedEventArgs e)
            {
                //Message de succés 
                MessageBox.Show("ca marche !");
     
     
            }

    j'att vos reponses avec impatience , un code qui semble correcte et qui marche pas ca fait pas du bien !!!

  11. #11
    Membre habitué
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2013
    Messages : 7
    Points : 139
    Points
    139
    Par défaut
    Remplace ce code
    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
    private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
            {
     
                try
                {
     
                    ServiceConsum.Service1Client client = new ServiceConsum.Service1Client();
                    client.SelectSocieteAsync(list);
                    this.listpicker.ItemsSource = list;
                    client.SelectSocieteCompleted += new EventHandler<SelectSocieteCompletedEventArgs>(client1_SelectSocieteCompleted);
     
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
     
            private void client1_SelectSocieteCompleted(object obj, ServiceConsum.SelectSocieteCompletedEventArgs e)
            {
                //Message de succés 
                MessageBox.Show("ca marche !");
     
     
            }
    Par celui la
    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
     
    private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
            {
     
                try
                {
     
                    ServiceConsum.Service1Client client = new ServiceConsum.Service1Client();
                    client.SelectSocieteAsync(list);
     
                    client.SelectSocieteCompleted += new EventHandler<SelectSocieteCompletedEventArgs>(client1_SelectSocieteCompleted);
     
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
     
            private void client1_SelectSocieteCompleted(object obj, ServiceConsum.SelectSocieteCompletedEventArgs e)
            {
                 if(e.Error == null)
                {
                    this.listpicker.ItemsSource = e.Result;
                     //Message de succés 
                    MessageBox.Show("ca marche !");
                }
            }

  12. #12
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 20
    Points : 11
    Points
    11
    Par défaut
    Bonsoir Merci encore mais encore ça ne marche pas pourtant la modification que vous m'avez suggérer

    donc???

  13. #13
    Membre habitué
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2013
    Messages : 7
    Points : 139
    Points
    139
    Par défaut
    Qu'est ce qui ne marche pas ? vous obtenez une exception ? rien ne s'affiche à l’écran ?.

    Ton application elle cible quelle version Windows Phone 7.0 7.1 8.0 ? si c'est la version 8 assure toi que l’émulateur a bien un accès à ton réseau local(en modifiant les paramètres de ta machine virtuelle dans le gestionnaire Hyper-V).

    Dans ta fonction "List<string> SelectSociete(List<string nom)" enlève le paramètre ça ne te sert a rien.

    Le control ListPicker tu la déclaré correctement dans ton fichier XAML?

    Assure toi que le service web marche correctement en dehors de ton app Windows Phone.

    Sinon a part ça on pourras pas t'aider d'avantager donne nous le code complet de ton projet (fichier XAML et .cs ).

  14. #14
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 20
    Points : 11
    Points
    11
    Par défaut
    y a aucune exception ! je travail avec la version 7.1

    Dans ma fonction "List<string> SelectSociete(List<string nom)" pourquoi supprimer le paramètre puisque lors de l'appel je passe une liste pour qu'elle se rempli !! sinn comment remplir cette liste sans la passer en parametre?!

    ListPicker est bien declarée j'ai déja testé de la remplir par une liste statique et ca marche .
    et oui j'ai testé mon serviceweb en dehor de l'app mobile et il retourne bien une liste des enregistrements voulus .
    j'ai fais un teste pour recuperer le nombre d'elements de ma liste(compteur) apres l'avoir passer comme parametre dans ma fonction et il retourne 0 donc la liste ne se rempli pas

    pour mon code complet alors le voilà :

    code xaml de votre_auto_car.xaml de mon app mobile:
    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
     
    <phone:PhoneApplicationPage 
        x:Class="garet.votre_auto_car"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
        shell:SystemTray.IsVisible="True" BorderBrush="#6CEFCACB" Loaded="PhoneApplicationPage_Loaded">
     
     
        <phone:PhoneApplicationPage.Resources>
            <DataTemplate x:Name="lpkItemTemplate">
                <TextBlock Text="{Binding Country}" />
            </DataTemplate>
            <DataTemplate x:Name="lpkFullItemTemplate">
                <TextBlock Text="{Binding Country}" />
            </DataTemplate>
        </phone:PhoneApplicationPage.Resources>
     
        <!--LayoutRoot est la grille racine où tout le contenu de la page est placé-->
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
     
            <!--TitlePanel contient le nom de l'application et le titre de la page-->
            <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
                <TextBlock x:Name="ApplicationTitle" Text="MON APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
                <TextBlock x:Name="PageTitle" Text="Votre autocar" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
            </StackPanel>
            <!--ContentPanel - placez tout contenu supplémentaire ici-->
            <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <toolkit:ListPicker FullModeItemTemplate="{Binding lpkFullItemTemplate}" ItemTemplate="{Binding lpkItemTemplate}"
                    x:Name="listpicker" Margin="12,100,23,180" />
                <TextBlock Height="30" HorizontalAlignment="Left" Margin="12,51,0,0" Name="textBlock1" Text="Choisir un Autocar" VerticalAlignment="Top" />
            </Grid>
     
        </Grid>
     
        </phone:PhoneApplicationPage>
    code de Service1.svc.cs :
    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
    73
    74
    75
    76
    77
    78
    79
    80
    81
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.Text;
    using MySql.Data.MySqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using System.Collections;
     
    namespace wcfGService1
    {
     
       public class Service1 : IService1
        {
            public string GetData(int value)
            {
                return string.Format("You entered: {0}", value);
            }
     
            public CompositeType GetDataUsingDataContract(CompositeType composite)
            {
                if (composite == null)
                {
                    throw new ArgumentNullException("composite");
                }
                if (composite.BoolValue)
                {
                    composite.StringValue += "Suffix";
                }
                return composite;
            }
     
            public List<string> SelectSociete(List<string> nom)
            {
                nom = new List<string>();
                //Object MysqlConnection
                MySqlConnection connection;
                string server;  
                string database;       
                string uid;   
                string password;
     
                server = "localhost";
                database = "gare_tetouan";
                uid = "root";
                password = "";
     
                string connectionString;
                connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
                connection = new MySqlConnection(connectionString);
     
                connection.Open();
     
                string query = "SELECT nom_societe FROM `societe`"; 
                MySqlCommand cmd = new MySqlCommand(query, connection);
                cmd.ExecuteNonQuery();
                MySqlDataReader reader = cmd.ExecuteReader();
     
                  while (reader.Read()) 
                    {
     
                        nom.Add(reader["nom_societe"].ToString());
     
                      }
     
                reader.Close();           
                connection.Close();
     
                return nom;
     
     
            }
     
        }
    }
    code de IService1.cs:
    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
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Collections;
     
    namespace wcfGService1
    {
        [ServiceContract]
        public interface IService1
        {
     
            [OperationContract]
            List<string> SelectSociete(List<string> nom); 
     
            [OperationContract]
            string GetData(int value);
     
            [OperationContract]
            CompositeType GetDataUsingDataContract(CompositeType composite);
     
            // TODO: ajoutez vos opérations de service ici
        }
     
     
         [DataContract]
        public class CompositeType
        {
            bool boolValue = true;
            string stringValue = "Hello ";
     
            [DataMember]
            public bool BoolValue
            {
                get { return boolValue; }
                set { boolValue = value; }
            }
     
            [DataMember]
            public string StringValue
            {
                get { return stringValue; }
                set { stringValue = value; }
            }
        }
    }
    code votre_auto_car.xaml.cs:

    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
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    using garet.ServiceConsum;
    using System.Collections;
     
    namespace garet
    {
        public partial class votre_auto_car : PhoneApplicationPage
        {
     
             List<string> list = new List<string>();
     
            public votre_auto_car() 
            {
                InitializeComponent();
     
            }
     
     
            private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
            {
     
                try
                {
     
                    ServiceConsum.Service1Client client = new ServiceConsum.Service1Client();
                    client.SelectSocieteAsync(list);
     
                    client.SelectSocieteCompleted += new EventHandler<SelectSocieteCompletedEventArgs>(client1_SelectSocieteCompleted);
     
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
     
            private void client1_SelectSocieteCompleted(object obj, ServiceConsum.SelectSocieteCompletedEventArgs e)
            {
                if (e.Error == null)
                {
                    MessageBox.Show(list.Count.ToString());
                    this.listpicker.ItemsSource = e.Result;
                    //Message de succés 
                    MessageBox.Show("ca marche !");
                }
            }
     
        }
    }
    Alors voilà c'est mon code complet

    et Merci beaucouuuup

  15. #15
    Membre actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2008
    Messages
    242
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Conseil

    Informations forums :
    Inscription : Août 2008
    Messages : 242
    Points : 296
    Points
    296
    Par défaut
    Il faut d'abonner puis lancer ton service! Sinon, il ne saura jamais quoi appeler une fois le DL finit

  16. #16
    Membre habitué
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2013
    Messages : 7
    Points : 139
    Points
    139
    Par défaut
    C'est normal que ça ne marche pas il y pas mal d'erreurs dans ton code !

    Tout d'abord ta pas besoin de faire un ItemTemplate pour ton ListPicker parce que tes données sont de type string (d'après ton code tu récupère une liste de strings depuis ton WebService et dans ton template tu fais un Binding sur la propriété Country qui n'existe pas dans les models de ta collection)

    Pour ta fonction "SelectSociete(List<string> nom)" déclare le paramètre comme variable dans ta fonction( ce que tu fais n'est pas logique! C'est comme si tu prends ta barrette mémoire de ton pc et tu va le donner à un serveur distant et tu lui demande de prendre tes données , dans ton cas ça marche, parce que tu fais une allocation de mémoire au niveau du Service Web et quoi que tu passes comme paramètre tes données seront toujours ignorés/écrasés par ton service web).

    Aller bon courage tu y presque

    EDIT : Et bien sur n'oublie pas de t'assurer que ton Service Web est démarré avant de lancer l'application mobile

  17. #17
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 20
    Points : 11
    Points
    11
    Par défaut
    okkk pour listpicker c bon j'ai corrigé comme suit:
    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
     
    <phone:PhoneApplicationPage 
        x:Class="garet.votre_auto_car"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
        shell:SystemTray.IsVisible="True" BorderBrush="#6CEFCACB" Loaded="PhoneApplicationPage_Loaded">
     
     
        <!--LayoutRoot est la grille racine où tout le contenu de la page est placé-->
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
     
            <!--Titleanel contient le nom de l'application et le titre de la page-->
            <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
                <TextBlock x:Name="ApplicationTitle" Text="MON APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
                <TextBlock x:Name="PageTitle" Text="Votre autocar" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
            </StackPanel>
            <!--ContentPanel - placez tout contenu supplémentaire ici-->
            <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <toolkit:ListPicker Header="Choisir un Autocar" FullModeItemTemplate="{Binding lpkFullItemTemplate}"
                    x:Name="listpicker" Margin="12,27,23,180" />
    P
            </Grid>
     
        </Grid>
     
        </phone:PhoneApplicationPage>
    mais pour ma fonction comment déclarer le paramètre comme variable dans ma fonction voulez vous dire par exemple

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    public List<string> SelectSociete()
            {
               List<string> nom = new List<string>();
    si c'est ce que vous voulez dire alors comment l'appeler pour remplir ma list???

  18. #18
    Membre habitué
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Juin 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2013
    Messages : 7
    Points : 139
    Points
    139
    Par défaut
    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
     
    <phone:PhoneApplicationPage 
        x:Class="garet.votre_auto_car"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
        xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
        FontFamily="{StaticResource PhoneFontFamilyNormal}"
        FontSize="{StaticResource PhoneFontSizeNormal}"
        Foreground="{StaticResource PhoneForegroundBrush}"
        SupportedOrientations="Portrait" Orientation="Portrait"
        mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
        shell:SystemTray.IsVisible="True" BorderBrush="#6CEFCACB" Loaded="PhoneApplicationPage_Loaded">
     
     
        <!--LayoutRoot est la grille racine où tout le contenu de la page est placé-->
        <Grid x:Name="LayoutRoot" Background="Transparent">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
     
            <!--Titleanel contient le nom de l'application et le titre de la page-->
            <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
                <TextBlock x:Name="ApplicationTitle" Text="MON APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
                <TextBlock x:Name="PageTitle" Text="Votre autocar" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
            </StackPanel>
            <!--ContentPanel - placez tout contenu supplémentaire ici-->
            <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
                <toolkit:ListPicker Header="Choisir un Autocar"               x:Name="listpicker" Margin="12,27,23,180" />
    P
            </Grid>
     
        </Grid>
     
        </phone:PhoneApplicationPage>
    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
     
    public List<string> SelectSociete()
            {
                //test = "11";
     
               List<string> nom = new List<string>();
                //Object MysqlConnection
                MySqlConnection connection;
                string server;  
                string database;       
                string uid;   
                string password;
     
                server = "localhost";
                database = "gare_tetouan";
                uid = "root";
                password = "";
     
                string connectionString;
                connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
                connection = new MySqlConnection(connectionString);
     
                connection.Open();
     
                string query = "SELECT nom_societe FROM `societe`"; 
                MySqlCommand cmd = new MySqlCommand(query, connection);
                cmd.ExecuteNonQuery();
                MySqlDataReader reader = cmd.ExecuteReader();
     
                  while (reader.Read()) 
                    {
                        nom.Add(reader["nom_societe"].ToString());
     
                      }
     
                reader.Close();           
                connection.Close();
     
                return nom;
     
     
            }

  19. #19
    Membre à l'essai
    Femme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    20
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Mai 2011
    Messages : 20
    Points : 11
    Points
    11
    Par défaut
    Suis vraiment dsl pour derangement et Merci beaucoup c'est exactement ce que j'ai fais avec le code de mon xaml.cs suivant:
    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
     
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Microsoft.Phone.Controls;
    using garet.ServiceConsum;
    using System.Collections;
     
    namespace garet
    {
        public partial class votre_auto_car : PhoneApplicationPage
        {
     
             public votre_auto_car() //constructeur
            {
                InitializeComponent();
            }
     
     
            private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
            {
                List<string> list = new List<string>();
     
                try
                {
                    ServiceConsum.Service1Client client = new ServiceConsum.Service1Client();
                    client.SelectSocieteAsync(list);
                    MessageBox.Show(list.Count.ToString());
     
                    client.SelectSocieteCompleted += new EventHandler<SelectSocieteCompletedEventArgs>(client1_SelectSocieteCompleted);
     
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
     
            private void client1_SelectSocieteCompleted(object obj, ServiceConsum.SelectSocieteCompletedEventArgs e)
            {
                if (e.Error == null)
                {
     
                    this.listpicker.ItemsSource = e.Result;
                    //Message de succés 
                    MessageBox.Show("ca marche !");
                }
            }
     
        }
    }
    y a quelque chose qui cloche là

    ???

  20. #20
    Membre actif
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2008
    Messages
    242
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Conseil

    Informations forums :
    Inscription : Août 2008
    Messages : 242
    Points : 296
    Points
    296
    Par défaut
    Tu regardes les messages que je poste ou bien?

    Tu veux du code, sinon, le français pour expliquer, c'est trop compliqué? Trop abstrait?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    client.SelectSocieteCompleted += new EventHandler<SelectSocieteCompletedEventArgs>(client1_SelectSocieteCompleted);
    client.SelectSocieteAsync(list);
    Et pas
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    client.SelectSocieteAsync(list);
    client.SelectSocieteCompleted += new EventHandler<SelectSocieteCompletedEventArgs>(client1_SelectSocieteCompleted);
    Comment tu veux qu'ils connaissent l’événement à lancer après avoir fini de DL sinon?

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. Réponses: 4
    Dernier message: 30/09/2011, 16h06
  2. [Oracle] probleme d'affichage des resultats de la requete select
    Par gigabit32 dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 29/06/2011, 17h22
  3. [MySQL] requete SELECT retournant une seule ligne
    Par hermann.geiger dans le forum SGBD
    Réponses: 12
    Dernier message: 19/09/2008, 08h34
  4. aide requete select d'une table dans une autre table
    Par alexkickstand dans le forum VBA Access
    Réponses: 1
    Dernier message: 24/10/2007, 22h09
  5. requete select dans une text box
    Par galaad666 dans le forum IHM
    Réponses: 5
    Dernier message: 29/11/2006, 13h55

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