0
HI我正在創建WCF服務,我已創建三個(問題,答案和類別)類創建一個類庫項目並使用它們的DLL創建服務,如下面的代碼WCF使用相同的外部錯誤引發錯誤
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_是階級答案的全球目標是在
using QuestionsAnswers;
命名空間現在我用我的客戶相同的命名空間,並使用相同的服務調用該方法,但給我的錯誤以下是代碼在我的客戶端
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)
{
}
}
我使用相同的參考
using QuestionsAnswers;
我提示以下錯誤:
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
任何人可以幫我
的可能的複製[CS0120:一個對象引用是所必需的非靜態字段,方法或屬性「富」](https://stackoverflow.com/questions/498400/cs0120-an-object-reference -is-需要換的-非靜態場法-或丙) –