I have written a web service which can be called from a javascript. It's all working fine but i notice that more properties are being returned than i expected...
url: http://localhost/intranet/Contacts.asmx/ContactsDirectory
In short, it reads the employees from a database and adds them to a list. Note that i am only adding 5 of the 13 properties available:
foreach (DataRow row in ResultsDataTable.Rows)
{
var Employee = new Employees();
Employee.Firstname = row["FIRSTNAME"].ToString();
Employee.Surname = row["SURNAME"].ToString();
Employee.PostTitle = row["POST"].ToString();
Employee.Department = row["DEPTARTMENT"].ToString();
Employee.Email = row["EMAIL"].ToString();
employees.Add(Employee);
}
My Employees class with the 13 properties:
public class Employees
{
public string PersonRef;
public string Firstname;
public string Surname;
public string PrefName;
public string Telephone;
public string PostRef;
public string PostTitle;
public string Department;
public string Section;
public string Location;
public string Email;
public string Manager;
public string ManagersEmail;
}
My AJAX request:
xhr = $.ajax({
type: 'POST',
url: './intranet/Contacts.asmx/ContactsDirectory',
data: JSON.stringify({ Name: "Scott" }),
contentType: 'application/json; charset=utf-8',
dataType: 'json'
});
You can see from the response below that the Properties Manager and ManagersEmail are being returned, but they weren't in my list! How do i prevent this? Note: i can't remove any of the properties from my class as other web services use these properties.