在 Webservice 返回 IList 数据

作者:互联网   出处:控件中国网   2014-11-05 19:21:48   阅读:1

在 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; } 

         } 

     } 

}
 

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat