WCF clent/Serveur : Aidez moi a trouver l'erreur svp

Houbie87 Messages postés 14 Date d'inscription vendredi 15 février 2008 Statut Membre Dernière intervention 18 novembre 2012 - 6 sept. 2012 à 13:53
Whismeril Messages postés 19028 Date d'inscription mardi 11 mars 2003 Statut Non membre Dernière intervention 24 avril 2024 - 8 sept. 2012 à 17:20
Bonjour ,
Je développement une appli client serveur en c#.Mon code ci-dessous me génère le message d'erreur suivant :
"La méthode surchargée ... possède arguments non valide"

Aidez moi svp a trouver ce qui cloche. Merci !
---->CLient
Private void btn_EnregChamps_Click(object sender, EventArgs e)
        {// champsSelect  est une listebox
           
            
            foreach (object item in ChampsSelect.Items)
            {
              
                string Champ_id = Client.Champ_Recherche((ChampsSelect.Tag as List<Champ>), item.ToString());
               
            }
           
        }


---->Serveur
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.IO;
using System.Configuration;
using System.Diagnostics;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Odbc;
using System.Runtime.Serialization;
using Model;
using Infragistics.Win.UltraWinTree;


namespace eDipWCFLibrary
{
    
    [ServiceContract()]
    public interface IService 
    {
        
        [OperationContract]
        string Champ_Recherche(List<Champ> chps, string Valeur);
        
       
    }
    
 
    public partial class Service : IService 
    {
         public string Champ_Recherche(List<Champ> chps, string Valeur)
        {
            foreach (Champ chp in chps)
            {
                string chpval = string.Format("{0} - [{1}]", chp.NOM, chp.LIBELLE);
                if (chpval == Valeur)
                {
                    return chp.CHAMP_ID;
                }
            }
            return "";
        }
      }
}

1 réponse

Whismeril Messages postés 19028 Date d'inscription mardi 11 mars 2003 Statut Non membre Dernière intervention 24 avril 2024 656
8 sept. 2012 à 17:20
Bonjour,

je pense que ChampsSelect.Tag n'est pas du type List<Champ>, donc le cast ne fonctionne pas et la signature de la méthode n'est pas bonne.
A moins que ce type de cast ne soit pas le bon, as tu essayé
(ChampsSelect.Tag)List<Champ>

?

Un autre point, manifestement ta méthode Champ_Recherche sert à retourner un champ spécifique ou son ID, à partir d'une string.
Pourquoi ne pas utiliser la méthode Find des list plutôt que la boucle, c'est fait pour.
En partant du principe que ChampsSelect.Tag est bien du type List<Champ>:
foreach (object item in ChampsSelect.Items)
            {
              
                
                Champ  toto ((ChampsSelect.Tag)List<Champ>).Find(delegate (Champ titi) {return item.ToString() string.Format("{0} - [{1}]", titi.NOM, titi.LIBELLE);});
               string Champ_id = toto.CHAMP_ID;;
            }


J'ai tapé de tête, il y a peut-être quelques erreurs...

Whismeril
0
Rejoignez-nous