for format) 代码 current text == 判断 tex
- public class MyService : IService
- {
- public Message GetXml(string format)
- {
- webOperationContext context = WebOperationContext.Current;
- Book b = new Book
- {
- BookName = "卖女孩的小火柴",
- Price = 25.2M,
- BarCode = "2811365801"
- };
- Message msgreturn = null;
- // 判断格式
- if (format.ToLower() == "xml")
- {
- msgreturn = context.CreateXmlResponse<Book>(b);
- }
- else
- {
- msgreturn = context.CreateJsonResponse<Book>(b);
- }
- return msgreturn;
- }
- }
WCF 输出 JSON
来源: http://www.bubuko.com/infodetail-2128399.html