HI I am creating WCF service for which I have Created three (Questions,Answers and Categories) classes by creating a class library project and used their DLL for creating the service as in the below code
public Answers InsertAnswer(Answers answer)
{
try
{
answer_ = new Answers();
cs = ConfigurationManager.ConnectionStrings[csName].ConnectionString;
using (con = new SqlConnection(cs))
{
cmd = new SqlCommand("InsertAnswer", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@answer", answer.Answer);
cmd.Parameters.AddWithValue("@questionId", answer.QuestionId);
con.Open();
cmd.ExecuteNonQuery();
answer_ = GetAnswer(answer);
}
}
catch (Exception ex)
{
}
finally
{
con.Close();
con.Dispose();
cmd.Dispose();
}
return answer_;
}
answer_ is Global object of class Answers which is under
using QuestionsAnswers;
namespace Now I am using the same namespace in my client and used the same service for calling the method but gives me error Below is the code on my client side
public void InserQuestionAnswer(QA qaParam)
{
try
{
Answers answer = new Answers();
answer.QuestionId = 1;
answer.Answer = qaParam.Answer.ToString();
QuestionsAnswersService.QuestionAnswerServiceClient questionAnswerService = new QuestionsAnswersService.QuestionAnswerServiceClient("BasicHttpBinding_IQuestionAnswerService");
questionAnswerService.InsertAnswer(answer);
}
catch (Exception ex)
{
}
}
I am using the Same reference
using QuestionsAnswers;
I am getting the below error
Severity Code Description Project File Line Suppression State
Error CS0120 An object reference is required for the non-static field,
method, or property 'QAaspx.InserQuestionAnswer(QA)' QASamapleUI E:\Rohit
Gupta\PracticeProjects\WebApp\QASamapleUI\QASamapleUI\QAaspx.aspx.cs 25
Active
Can anybody please help me