微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从WCF REST服务返回XML列表

如何解决从WCF REST服务返回XML列表

| 我有WCF Rest服务,当前正在返回类型为“ Book”的列表。该服务运行正常,返回的信息不是xml格式。这使得无法解析,我如何使其以xml格式显示。 或者我可以通过使用客户端中的类类型进行解析? 谢谢你的帮助 服务
[WebGet(UriTemplate = \"ListAllBooks\",ResponseFormat=Webmessageformat.Xml,BodyStyle= WebMessageBodyStyle.Wrapped)]
    List<Book> ListAllBooks()
    {
        List<Book> bookList = new List<Book>();
        Book aBook;
        String query = \"SELECT ID,ISBN,Title,Author,Genre,Format,Inventory,Price FROM books\";
        sqlDataReader reader = queryDB(query,connectionString);
        while (reader.Read())
        {
            aBook = new Book();
            aBook.Author = reader[\"Author\"].ToString();
            aBook.Title = reader[\"Title\"].ToString();
            aBook.ID = reader[\"ID\"].ToString();
            aBook.Inventory = Convert.ToInt32(reader[\"Inventory\"]);
            aBook.ISBN = reader[\"ISBN\"].ToString();
            aBook.Price = Convert.Todouble(reader[\"Price\"]);
            aBook.Genre = reader[\"Genre\"].ToString();
            aBook.Format = reader[\"Format\"].ToString();
            bookList.Add(aBook);
        }
        return bookList;
    }
打字本
    public class Book
    {
        public String ID { get; set; }
        public String ISBN { get; set; }
        public String Title { get; set; }
        public String Author { get; set; }
        public String Genre { get; set; }
        public String Format { get; set; }
        public int Inventory { get; set; }
        public double Price { get; set; }
    }
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。