Bonjour,
Dans mon web service, j'ai une méthode GetEtudiantsByClasse, je dois donner comme paramètre l'id de la classe, et la méthode doit retourner une liste d'étudiants. pour cela, j'ai implémenter ma base de donnée sous sql server (deux tables étudiants et classes), j'ai mis une une procédure stockée au niveau sgbd que j'ai appelée : ma classe entité c'est :
Classe :
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
| using System;
using System.Collections.Generic;
using System.Text;
namespace ClSCOLARITE.Entity
{
public class Classe
{
#region Fields
private string m_libelle;
private string m_niveau;
#endregion
#region Constructs
public Classe()
{
}
#endregion
#region Properties
[System.ComponentModel.Browsable(true)]
public string Libelle
{
get { return m_libelle; }
set { m_libelle = value; }
}
[System.ComponentModel.Browsable(true)]
public string Niveau
{
get { return m_niveau; }
set { m_niveau = value; }
}
#endregion
}
} |
Etudiant :
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.Text;
namespace ClSCOLARITE.Table
{
class Etudiant : System.Collections.Generic.List<Entity.Etudiant>
{
#region Fields
private Data.Etudiant oBData;
#endregion
#region Constructors
public Etudiant()
{
oBData = new Data.Etudiant();
}
#endregion
#region Methods
public void LoadEtudiantsbyClasse(string classe)
{
System.Data.SqlClient.SqlDataReader oDBDataReader;
try
{
oDBDataReader = oBData.LoadEtudiantsbyClasse(classe);
while (oDBDataReader.Read() == true)
{
Entity.Etudiant oEtudiant;
oEtudiant = new Entity.Etudiant();
oEtudiant.ClEtudiant = Convert.ToString(oDBDataReader["ClEtudiant"]);
oEtudiant.Nom = Convert.ToString(oDBDataReader["Nom"]);
oEtudiant.Prenom = Convert.ToString(oDBDataReader["Prenom"]);
oEtudiant.Age = Convert.ToInt32(oDBDataReader["Age"]);
this.Add(oEtudiant);
}
oBData.CloseDataReader();
oBData.CloseConnection();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
} |
Au niveau Data :
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
| using System;
using System.Collections.Generic;
using System.Text;
namespace ClSCOLARITE.Data
{
public class Classe
{
#region Fields
Data.SqlClient m_SqlClient;
#endregion
#region Constructors
public Classe()
{
m_SqlClient = new SqlClient();
}
#endregion
#region Methodes
public System.Data.SqlClient.SqlDataReader LoadClasses()
{
System.Data.SqlClient.SqlDataReader oOleDbDataReader;
try
{
m_SqlClient.CreateCommand(System.Data.CommandType.StoredProcedure, "SelectClasses");
oOleDbDataReader = m_SqlClient.LoadList();
}
catch (Exception ex)
{
throw ex;
}
return oOleDbDataReader;
}
public void CloseDataReader()
{
try
{
m_SqlClient.CloseDataReader();
}
catch (Exception ex)
{
throw ex;
}
}
public void CloseConnection()
{
try
{
m_SqlClient.CloseConnection();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
} |
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
| using System;
using System.Collections.Generic;
using System.Text;
namespace ClSCOLARITE.Data
{
public class Etudiant
{
#region Fields
Data.SqlClient m_SqlClient;
#endregion
#region Constructors
public Etudiant()
{
m_SqlClient = new SqlClient();
}
#endregion
#region Methodes
public System.Data.SqlClient.SqlDataReader LoadEtudiantsbyClasse(string classe)
{
System.Data.SqlClient.SqlDataReader oOleDbDataReader;
try
{
m_SqlClient.CreateCommand(System.Data.CommandType.StoredProcedure, "SELECTEtudiantsByClasse");
m_SqlClient.AddCommandParameter("@ClasseLibelle", System.Data.SqlDbType.VarChar, classe);
oOleDbDataReader = m_SqlClient.LoadList();
}
catch (Exception ex)
{
throw ex;
}
return oOleDbDataReader;
}
public void CloseDataReader()
{
try
{
m_SqlClient.CloseDataReader();
}
catch (Exception ex)
{
throw ex;
}
}
public void CloseConnection()
{
try
{
m_SqlClient.CloseConnection();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
} |
Au niveau table :
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
| using System;
using System.Collections.Generic;
using System.Text;
namespace ClSCOLARITE.Table
{
class Classe : System.Collections.Generic.List<Entity.Classe>
{
#region Fields
private Data.Classe oBData;
#endregion
#region Constructors
public Classe()
{
oBData = new Data.Classe();
}
#endregion
#region Methods
#endregion
public void LoadClasses()
{
System.Data.SqlClient.SqlDataReader oDBDataReader;
try
{
oDBDataReader = oBData.LoadClasses();
while (oDBDataReader.Read() == true)
{
Entity.Classe oClasse;
oClasse = new Entity.Classe();
oClasse.Libelle = Convert.ToString(oDBDataReader["Libelle"]);
oClasse.Niveau= Convert.ToString(oDBDataReader["Niveau"]);
this.Add(oClasse);
}
oBData.CloseDataReader();
oBData.CloseConnection();
}
catch (Exception ex)
{
throw ex;
}
}
}
} |
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.Text;
namespace ClSCOLARITE.Table
{
class Etudiant : System.Collections.Generic.List<Entity.Etudiant>
{
#region Fields
private Data.Etudiant oBData;
#endregion
#region Constructors
public Etudiant()
{
oBData = new Data.Etudiant();
}
#endregion
#region Methods
public void LoadEtudiantsbyClasse(string classe)
{
System.Data.SqlClient.SqlDataReader oDBDataReader;
try
{
oDBDataReader = oBData.LoadEtudiantsbyClasse(classe);
while (oDBDataReader.Read() == true)
{
Entity.Etudiant oEtudiant;
oEtudiant = new Entity.Etudiant();
oEtudiant.ClEtudiant = Convert.ToString(oDBDataReader["ClEtudiant"]);
oEtudiant.Nom = Convert.ToString(oDBDataReader["Nom"]);
oEtudiant.Prenom = Convert.ToString(oDBDataReader["Prenom"]);
oEtudiant.Age = Convert.ToInt32(oDBDataReader["Age"]);
this.Add(oEtudiant);
}
oBData.CloseDataReader();
oBData.CloseConnection();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
} |
et au niveau de mon web service :
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
| using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
private ClSCOLARITE.Data.Etudiant oBData;
public Service()
{
//Supprimez les marques de commentaire dans la ligne suivante si vous utilisez des composants conçus
//InitializeComponent();
}
[WebMethod]
public string HelloWord()
{
return "hello Maria";
}
[WebMethod]
public void LoadEtudiantsbyClasse(string classe)
{
System.Data.SqlClient.SqlDataReader oDBDataReader;
try
{
oDBDataReader = oBData.LoadEtudiantsbyClasse(classe);
while (oDBDataReader.Read() == true)
{
ClSCOLARITE.Entity.Etudiant oEtudiant;
oEtudiant = new ClSCOLARITE.Entity.Etudiant();
oEtudiant.ClEtudiant = Convert.ToString(oDBDataReader["ClEtudiant"]);
oEtudiant.Nom = Convert.ToString(oDBDataReader["Nom"]);
oEtudiant.Prenom = Convert.ToString(oDBDataReader["Prenom"]);
oEtudiant.Age = Convert.ToInt32(oDBDataReader["Age"]);
this.Add(oEtudiant);
}
oBData.CloseDataReader();
oBData.CloseConnection();
}
catch (Exception ex)
{
throw ex;
}
}
} |
Je sais pas si je suis sur la bonne voie ou non ? mais j'ai une erreur que j'ai pas pu résoudre au niveau de mon web service :
il me dit que :
Erreur 1 'Service' ne contient pas de définition pour 'Add' C:\Inetpub\wwwroot\WsSCOLARITE\App_Code\Service.cs 44 22 http://localhost/WsSCOLARITE/
?
vous avez une idée ?
Partager