Bonjour à tous,

j'ai un petit problème, j'ai fait un webservice qui renvoi une datatable et j'ai l'erreur suivante.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: Cannot serialize the DataTable. DataTable name is not set.
y a t-il un moyen simple de retourner une datatable?

aujourd'hui le seul moyen d'avoir le résultat escompté:
1-faire une classe dont il y a autant de données membre que de colonne de mon DataTable.
2-déclarer des fonctions statiques du type convertTableauToDataTable et convertDataTableToTableau.
3-que le webservice me renvoi un tableau d'objet.

Ma Classe :
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
public class Commande {
        public int SITE;
        public string SUC_NOM_ABR;
        public int CAT;
        public decimal NBR_CDE;
        public decimal NBR_CDELIG;
        public decimal NBR_EXPED;
        public decimal NBR_ENVMAG;
        public decimal NBR_FACT;
 
        public Commande() { }
        static public DataTable TabToDataTable( Commande[] Cmd ) {
            DataTable Cmds = new DataTable();
            Cmds.Columns.Add( "SITE", typeof( int ) );
            Cmds.Columns.Add( "SUC_NOM_ABR", typeof( string ) );
            Cmds.Columns.Add( "CAT", typeof( int ) );
            Cmds.Columns.Add( "NBR_CDE", typeof( int ) );
            Cmds.Columns.Add( "NBR_CDELIG", typeof( int ) );
            Cmds.Columns.Add( "NBR_EXPED", typeof( int ) );
            Cmds.Columns.Add( "NBR_ENVMAG", typeof( int ) );
            Cmds.Columns.Add( "NBR_FACT", typeof( int ) );
 
            DataRow DR;
            for (int i = 0; i < Cmd.Length; i++) {
                DR = Cmds.NewRow();
                DR["SITE"] = int.Parse( Cmd[i].SITE.ToString() );
                DR["SUC_NOM_ABR"] = Cmd[i].SUC_NOM_ABR.ToString();
                DR["CAT"] = int.Parse( Cmd[i].CAT.ToString() );
                DR["NBR_CDE"] = int.Parse( Cmd[i].NBR_CDE.ToString() );
                DR["NBR_CDELIG"] = int.Parse( Cmd[i].NBR_CDELIG.ToString() );
                DR["NBR_EXPED"] = int.Parse( Cmd[i].NBR_EXPED.ToString() );
                DR["NBR_ENVMAG"] = int.Parse( Cmd[i].NBR_ENVMAG.ToString() );
                DR["NBR_FACT"] = int.Parse( Cmd[i].NBR_FACT.ToString() );
 
                Cmds.Rows.Add( DR );
 
            }
            return Cmds;
        }
        static public Commande[] DataTableToTableau( DataTable Commandes )
        {
            Commande[] Coms=new Commande[Commandes.Rows.Count];
 
            Commande Com ;
 
            for (int i = 0; i < Commandes.Rows.Count; i++) {
                Com = new Commande();
 
                Com.CAT = int.Parse( Commandes.Rows[i]["CAT"].ToString() );
                Com.NBR_CDE = int.Parse( Commandes.Rows[i]["NBR_CDE"].ToString() );
                Com.NBR_CDELIG = int.Parse( Commandes.Rows[i]["NBR_CDELIG"].ToString() );
                Com.NBR_ENVMAG = int.Parse( Commandes.Rows[i]["NBR_ENVMAG"].ToString() );
                Com.NBR_EXPED = int.Parse( Commandes.Rows[i]["NBR_EXPED"].ToString() );
                Com.NBR_FACT = 0;
                Com.SITE = int.Parse( Commandes.Rows[i]["SITE"].ToString() );
                Com.SUC_NOM_ABR = Commandes.Rows[i]["SUC_NOM_ABR"].ToString();
 
                Coms[i] = Com;
            }
            return Coms;
        }
Le webservice :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
[WebMethod]
    public Commande[] GetCommandes( string dateDeb, string DateFin, string Typo ) {
 
        DataTable Commandes = new DataTable();
        Commandes = FillTable(dateDeb,DateFin,Typo );
 
        Commande[] Coms=Commande.DataTableToTableau( Commandes );
 
        return Coms;
    }
Quelqu'un peut-il m'aider?
Merci d'avance.
ALCINA.