在 Webservice 返回 IList 数据
using System;
using System.Collections;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
[XmlInclude(typeof(Article))]
public IList GetArticleList()
{
IList result = new ArrayList();
for (int i = 0; i < 20; i++)
{
string title = string.Format("新闻标题-{0}", i);
string content = string.Format("新闻内容-{0}", i);
DateTime time = DateTime.Now.AddDays(i);
result.Add(new Article(title, content, time));
}
return result;
}
public class Article
{
private string title;
private string content;
private DateTime time;
public Article()
{
}
public Article(string title,string content,DateTime time)
{
this.title = title;
this.content = content;
this.time = time;
}
public string Title
{
get { return title; }
set { title = value; }
}
public string Content
{
get { return content; }
set { content = value; }
}
public DateTime Time
{
get { return time; }
set { time = value; }
}
}
}