I know this is an old theme but I had to write a sample app for demonstration in a tech forum. So reproducing here also.

Importantly, the DataTable/DataSet must be serializable.

ASMX Code:

    public class Service1 : System.Web.Services.WebService
    {
 
        [WebMethod]
        public DataTable HelloWorldDataSet()
        {
            DataTable dt = new DataTable("MyDataTable");
            dt.Columns.Add("column1",typeof(System.String));
            dt.Columns.Add("column2", typeof(System.String));
 
            DataRow dr = dt.NewRow();
            dr["column1"] = "blah1";
            dr["column2"] = "blee1";
            dt.Rows.Add(dr);
 
            dr = dt.NewRow();
            dr["column1"] = "blah2";
            dr["column2"] = "blee2";
            dt.Rows.Add(dr);
 
            return dt;
        }
    }
        private void button1_Click(object sender, EventArgs e)
        {
            helloservice.Service1 service = new WindowsFormsApplication1.helloservice.Service1();
            DataTable dt = service.HelloWorldDataSet();
        }

 

C# Code:

VN:F [1.1.6_502]
Rating: 0.0/5 (0 votes cast)
Share:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • DotNetKicks
  • LinkedIn
  • Live
  • MySpace
  • StumbleUpon
  • Technorati

Related posts:

  1. Convert a IEnumerable to DataTable with Reflection
  2. Reorder listbox items with JavaScript and ASP.NET
  3. Webservice tutorial with C#
  4. Get currently logged in user from a service running under LocalSystem account
  5. Get all table names from Microsoft Access (MDB) database file