Ok, I've been stuck in this error for quite some time now. Here is what I'm doing. I created a service library and added my service implementation logic. After that, I'm hosting it in an WCF application. But I keep on getting an error
The server encountered an error processing the request
while trying to browse the service.
Here is my code:
[DataContract(Namespace = "http://Collect-Info.com/Questions")]
public class Question
{
[DataMember]
public int ID;
[DataMember]
public string question;
[DataMember]
public int CategoryID;
[DataMember]
public int TypeID;
}
[DataContract(Namespace = "http://Collect-Info.com/Answers")]
public class Answer
{
[DataMember]
public int ID;
[DataMember]
public int PID;
[DataMember]
public int QuestionID;
[DataMember]
public string QAnswer;
[DataMember]
public int CategoryID;
}
[ServiceContract()]
public interface IInfoCollectService
{
[OperationContract()]
[WebGet(UriTemplate = "Questions", ResponseFormat = WebMessageFormat.Json)]
List<Question> GetAllQuestionList();
[OperationContract()]
[WebGet(UriTemplate = "Questions/{ID}", ResponseFormat = WebMessageFormat.Json)]
List<Question> GetQuestionListByCategory(string id);
[OperationContract()]
[WebGet(UriTemplate = "Answers", ResponseFormat = WebMessageFormat.Json)]
List<Answer> GetAllAnswerList();
[OperationContract()]
[WebGet(UriTemplate = "Answers/{ID}", ResponseFormat = WebMessageFormat.Json)]
List<Answer> GetAnswerListByCategory(string id);
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class InfoCollectService : IInfoCollectService
{
public List<Question> GetAllQuestionList()
{
var dt = (new DBHandler()).GetResult("Select * From Question");
var qQuestion = from t in dt.AsEnumerable()
select new Question()
{
ID = Int32.Parse(t["ID"].ToString()),
question = t["Question"].ToString(),
CategoryID = Int32.Parse(t["Category"].ToString()),
TypeID = Int32.Parse(t["Type"].ToString())
};
return qQuestion.ToList<Question>();
}
public List<Question> GetQuestionListByCategory(string id)
{
var dt = (new DBHandler()).GetResult("Select * From Question where Category = " + id);
if (dt.Rows.Count > 0)
{
var qQuestion = from t in dt.AsEnumerable()
select new Question()
{
ID = Int32.Parse(t["ID"].ToString()),
question = t["Question"].ToString(),
CategoryID = Int32.Parse(t["Category"].ToString()),
TypeID = Int32.Parse(t["Type"].ToString())
};
return qQuestion.ToList<Question>();
}
return null;
}
public List<Answer> GetAllAnswerList()
{
var dt = (new DBHandler()).GetResult("Select * From Answer");
var qAnswer = from t in dt.AsEnumerable()
select new Answer()
{
ID = Int32.Parse(t["ID"].ToString()),
PID = Int32.Parse(t["PID"].ToString()),
QuestionID = Int32.Parse(t["QuestionID"].ToString()),
QAnswer = t["QAnswer"].ToString(),
CategoryID = Int32.Parse(t["CategoryID"].ToString())
};
return qAnswer.ToList<Answer>();
}
public List<Answer> GetAnswerListByCategory(string id)
{
var dt = (new DBHandler()).GetResult("Select * From Answer where QuestionID = " + id);
if (dt.Rows.Count > 0)
{
var qQuestion = from t in dt.AsEnumerable()
select new Answer()
{
ID = Int32.Parse(t["ID"].ToString()),
PID = Int32.Parse(t["PID"].ToString()),
QuestionID = Int32.Parse(t["QuestionID"].ToString()),
QAnswer = t["QAnswer"].ToString(),
CategoryID = Int32.Parse(t["CategoryID"].ToString())
};
return qQuestion.ToList<Answer>();
}
return null;
}
}
Ok, when I just try to list all the questions using the URL as per my uri template specified :
http://www.domain.com/Service1.svc/Questions
I get that error
Note: I'm just testing this service on my local machine's IIS.