I created a webservice that returnes some categories from database. If i test with the client that WCF is offering everything is perfect.
I started building a client. I added a service reference to my service http://localhost/Transaction/transaction.svc
. I create a new instance of the client webservice
TransactionClient tc = new TransactionClient("BasicHttpEndpoint");
Category[] availableCategories = tc.GetAllCategories();
I get Object reference not set to an instance of an object
on the second line of code. The endpoint name is correct.
Any idea why the error ?
PS : if you need more code please let me know what to post. Thanks in advance.
Edit :
[OperationContract]
List<Category> GetAllCategories();
Implementation :
public List<Category> GetAllCategories()
{ return db.GetAllCategories()}
The service is working is i test with WCFClient, so the rest of my code must be corect.
This is the code that gets me the items from database. I try with the solution posted but the app did not stop.
List<Category> response = new List<Category>();
connect();
SqlCommand cmd = new SqlCommand("select id_category, name from tbl_category", conn);
try
{
dr = cmd.ExecuteReader();
while (dr.Read())
{
Category new_category = new Category();
new_category.id_category = int.Parse(dr["id_category"].ToString());
new_category.name = dr["name"].ToString();
response.Add(new_category);
}
}
catch (SqlException ex)
{
Console.Out.Write(ex.ToString());
}
finally
{
dr.Close();
conn.Close();
}
return response;