When I POST using my windows form app (second peace of code down) when I go to GET the student collection with buttonclick 2 into my datagrid nothing is showing I can hardcode the members and GET no problem, yet I cant POST? The response I get back says OK in the message box when I click button1 for my post? So not quite sure what I have done...
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "")]
void AddStudent(Student student);
XDocument xDoc = XDocument.Load(uri);
var students = xDoc.Descendants("Student")
.Select(n => new
{
StudentNo = n.Element("StudentID").Value,
Firstname = n.Element("FirstName").Value,
Surname = n.Element("LastName").Value
})
.ToList();
dataGridView1.DataSource = students;
}
ArrayOfStudent. Why do you form your xml manually instead of using an xml parser? what is the use of Student class if you don't use it for serializing/deserializing - L.B 2012-04-05 20:29
ArrayOfStudent not StudentL.B 2012-04-05 20:35
Student class to get the xml to post to server - L.B 2012-04-05 20:39
Are you running in Per Call Activation mode? If so, every client request gets a new dedicated service instance, so your List<> is being recreated as empty every time.
See this reference article. You'll have to persist your List between calls, either in a Cache or Database.
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]Garrith Graham 2012-04-06 01:57
Your AddStudent is not adding to the list
public void AddStudent(Student student)
{
student.StudentID.ToString();
student.FirstName.ToString();
student.LastName.ToString();
}
And GetStudentCollection is returning the same hard coded values.
static List<Student> students = new List<Student>();
public void AddStudent(Student student)
{
students.Add(student);
}
public List<Student> GetStudentCollection()
{
return students;
}
Addstudent is probably not working correctly. Can you put a breakpoint there and see if is being called with a properly formatted student - Anurag Ranjhan 2012-04-05 20:49
Your service is doing exactly what you wrote in code. ListStudents constantly returns the same list of the students, AddStudent do nothing with the list.
StudentIDorStudentNo,FirstNameorFirstname,LastNameorSurnameL.B 2012-04-05 20:14