我想通過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