WCF clent/Serveur : Aidez moi a trouver l'erreur svp
Houbie87
Messages postés14Date d'inscriptionvendredi 15 février 2008StatutMembreDernière intervention18 novembre 2012
-
6 sept. 2012 à 13:53
Whismeril
Messages postés19028Date d'inscriptionmardi 11 mars 2003StatutNon membreDernière intervention24 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 "";
}
}
}
Whismeril
Messages postés19028Date d'inscriptionmardi 11 mars 2003StatutNon membreDernière intervention24 avril 2024656 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>: