问题描述
|
我有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 (将#修改为@)