我想通过Web服务发送一个匿名对象。无论如何,我可以做到这一点,而无需手动创建一个类并将其转换为该类?目前它抛出一个异常说匿名对象不能序列化。如何序列化通过SOAP Web服务发送的匿名对象?
// 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;
}
在此先感谢。
编辑:这里是我的意思是通过手动创建一个类来返回,并与匿名对象填充一个例子...
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;
}
只是好奇,为什么你喜欢自动在公共领域实现的属性? – Kevin 2008-12-03 15:19:17