首页 > Windows开发 > 详细

WebService生成XML文档时出错。不应是类型XXXX。使用XmlInclude或SoapInclude属性静态指定非已知的类型。

时间:2019-01-20 20:39:15      阅读:434      评论:0      收藏:0      [点我收藏+]

情况是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

 

WebService生成XML文档时出错。不应是类型XXXX。使用XmlInclude或SoapInclude属性静态指定非已知的类型。

原文:https://www.cnblogs.com/chenh/p/10295999.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!