情况是SingleRoom和DoubleRoom是Room类的子类。在WebService中有一个方法是返回Room类。
public Room Get(int roomId) { return Room.Get(roomId); }
XmlSerializer在序列化时只能识别父类,而不能识别子类,所以导致序列化的错误。需要将[XmlInclude(typeof(SingleRoom))]和[XmlInclude(typeof(DoubleRoom))]同时加到WebService中。
[XmlInclude(typeof(SingleHouse))] [XmlInclude(typeof(DoubleHouse))] public class RoomService : System.Web.Services.WebService