Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Typed Dataset and web service
Message
From
19/04/2008 20:22:55
 
 
To
13/04/2008 15:09:02
General information
Forum:
ASP.NET
Category:
Web Services
Miscellaneous
Thread ID:
01310273
Message ID:
01311910
Views:
25
Jeez, where *is* everyone? No one has answered this question in 6 days? I'm sorry Alan, I surely would have answered this sooner had I been around (I've been out of town and offline for a bit).

Anyway, I haven't looked at everything, but I see a pretty glaring error right off the bat, and that's probably causing you the problem (although, in 6 days, you may have figured it out yourself already <g>):

Your WebMethod is this:
    [WebMethod(Description = "Returns a dataset according to desired id")]
    public DataSet GetDeptById(short id)
    {
      // create dataset (ds), datatable (dt) and table adapter (adapter)
      dsDept ds = new dsDept();
      dsDept.DepartmentDataTable dt = new dsDept.DepartmentDataTable(ds.Tables[0]);
      dsDeptTableAdapters.DepartmentTableAdapter adapter =
        new dsDeptTableAdapters.DepartmentTableAdapter();

      // call adapter method to fill datatable according to requested id
      adapter.FillByID(dt, id);

      return ds;
    }
The problem is that you're filling a DataTable that is not actually part of the new DataSet you just instantiated.

Try this instead:
    [WebMethod(Description = "Returns a dataset according to desired id")]
    public DataSet GetDeptById(short id)
    {
      // create dataset (ds), datatable (dt) and table adapter (adapter)
      dsDept ds = new dsDept();
      dsDeptTableAdapters.DepartmentTableAdapter adapter =
        new dsDeptTableAdapters.DepartmentTableAdapter();

      // call adapter method to fill datatable according to requested id
      adapter.FillByID(ds.DepartmentDataTable, id);

      return ds;
    }
Also I think I should mention that it's generally not a good idea to return DataSets from Web Service methods ... unless your Web Service is never intended to be used by other than .NET clients. Returning a DataSet instead of an XML string is not very cross-platform-friendly. But, that's another topic. <g>

~~Bonnie





>I've been following Kevin M's thread #1309187 as it evolved, hoping it would give me the answer I want, but as luck would have it...
>
>Anyway, let me preface this by saying that Yankee Stadium couldn't hold what I don't know about .Net.
>
>Now, the question is, why can't I get a typed dataset to return actual data from a web service?
>
>I'm using the AdventureWorks_Data database in MS SqlServer.
>
>dsDept is a typed dataset created through VS 2005. It uses a stored proc to bring back the data. The stored proc is simply
>
Select * From HumanResources.Department where DepartmentID = @id
.
>
>"catsnjazz" is the name of my computer.
>
>When I execute the stored proc from VS 2005's Server Explorer, it brings back the correct data.
>
>Here is the code for the web service stripped right down to it's knickers. I took out the business objects etc, so that it would be as simple as possible to show the problem.
>
>Following the web service code, is the code that calls the web service (also stripped right down). It consists of a form with 4 text boxes and a button that when clicked starts the process.
>
>So, any idea what I'm doing wrong? Don't worry about hurting my feelings if it's something really dumb. And let me point out that if I don't use a typed dataset - if I create a normal dataset, command, datatable, and adapter in my code and return the dataset, it works like I would expect and returns the data requested. With the typed dataset, all I get back is the schema with no data.
>
>Oh, one more thing. After the line "adapter.FillByID(dt, id);" in the web service, I even tried adding "ds.AcceptChanges" and I also tried "dt.AcceptChanges", both to no avail.
>
>
// Web Service
>
>using System;
>using System.Data;
>using System.Web;
>using System.Collections;
>using System.Web.Services;
>using System.Web.Services.Protocols;
>using System.ComponentModel;
>
>namespace wsAwDept
>{
>  /// <summary>
>  /// Summary description for svcAwDept
>  /// </summary>
>  [WebService(Namespace = "http://catsnjazz/")]
>  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
>  [ToolboxItem(false)]
>  public class svcAwDept : System.Web.Services.WebService
>  {
>
>    [WebMethod(Description = "Returns a dataset according to desired id")]
>    public DataSet GetDeptById(short id)
>    {
>      // create dataset (ds), datatable (dt) and table adapter (adapter)
>      dsDept ds = new dsDept();
>      dsDept.DepartmentDataTable dt = new dsDept.DepartmentDataTable(ds.Tables[0]);
>      dsDeptTableAdapters.DepartmentTableAdapter adapter =
>        new dsDeptTableAdapters.DepartmentTableAdapter();
>
>      // call adapter method to fill datatable according to requested id
>      adapter.FillByID(dt, id);
>
>      return ds;
>    }
>  }
>}
>
>
>
// Calling program
>
>using System;
>using System.Collections.Generic;
>using System.ComponentModel;
>using System.Data;
>using System.Drawing;
>using System.Text;
>using System.Windows.Forms;
>
>namespace awdatatest
>{
>	public partial class Form1 : Form
>	{
>		// create service, dataset and datatablereader
>		catsnjazz.svcAwDept ws = new catsnjazz.svcAwDept();
>		DataSet departmentDS = new DataSet();
>		DataTableReader dr;
>
>		public Form1()
>		{
>			InitializeComponent();
>		}
>
>		private void btnStart_Click(object sender, EventArgs e)
>		{
>			// create a dataset using service and id of 11
>			departmentDS = ws.GetDeptById(11);
>			// set the datatablereader to the table in the dataset
>			dr = departmentDS.CreateDataReader(departmentDS.Tables[0]);
>			
>			// see if we have the right schema for the table
>			MessageBox.Show(dr.GetName(0) + "\r\n" +
>								dr.GetName(1) + "\r\n" +
>								dr.GetName(2) + "\r\n" +
>								dr.GetName(3));
>
>			if (dr.HasRows)
>			{
>				// move to 1st record and display the data
>				dr.Read();
>				this.showData(dr);
>			}
>			else
>			{
>				// no data in the dataset - WHY NOT??
>				MessageBox.Show("No rows returned");
>			}
>		}
>
>		// display the data in the dataset
>		private void showData(DataTableReader dr)
>		{
>				this.txtDepartmentID.Text = dr.GetValue(0).ToString();
>				this.txtName.Text = dr.GetValue(1).ToString();
>				this.txtGroupName.Text = dr.GetValue(2).ToString();
>				this.txtModifiedDate.Text = dr.GetValue(3).ToString();
>		}
>	}
>}
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform