I need to call a wcf service method in my project, if I have a method called getPrimaryList, how do I call it?
[OperationContract]
public List<PrimaryClass> getPrimaryList()
{
string priConn = System.Configuration.ConfigurationManager.ConnectionStrings["SchoolConnectionString"].ConnectionString;
var priList = new List<PrimaryClass>();
using (SqlConnection conn = new SqlConnection(priConn))
{
const string sql = @"SELECT PrimarySchool,TopHonour,Cca,TopStudent,TopAggregate,TopImage FROM [Primary]";
conn.Open();
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
SqlDataReader dr = cmd.ExecuteReader(
CommandBehavior.CloseConnection);
if (dr != null)
while (dr.Read())
{
var pri = new PrimaryClass
{
PrimarySchool = dr.GetString(0),
TopHonour = dr.GetString(1),
Cca = dr.GetString(2),
TopStudent = dr.GetString(3),
TopAggregate = dr.GetString(4),
TopImage = dr.GetString(5)
};
priList.Add(pri);
}
return priList;
}
}
}
Open the project that needs to call the service.
Add a Service Reference to the WCF Service.
Make an instance of the generated proxy/client class and call the method.
(this answer is nearly as general as your question, if you need more details you have to ask for them specifically)
EDIT
Example (the use of the dispatcher is not really needed here):