I am trying to send an anonymous object over a web service. Is there anyway I can do this without manually creating a class and casting it to that class? Currently its throwing an exception saying Anonymous object could not be serialized.
// Some code has been removed here to simplify the example.
[WebMethod(EnableSession = true)]
public Response GetPatientList() {
var patientList = from patient in ((User)Session["user"]).Practice.Patients
select new {
patientID = patient.PatientID,
status = patient.Active ? "Active" : "Inactive",
patientIdentifier = patient.PatientIdentifier,
physician = (patient.Physician.FirstName + " " + patient.Physician.LastName).Trim(),
lastModified = patient.Visits.Max(v => v.VisitDate)
};
return patientList;
}
Thanks in advance.
Edit: Here is an example of what I mean by manually creating a class to return and fill it with the anonymous object...
public class Result {
public bool success;
public bool loggedIn;
public string message;
}
public class PracticeInfoResult : Result {
public string practiceName;
public string address;
public string city;
public string state;
public string zipCode;
public string phone;
public string fax;
}