Answer/Comments at the end. (To avoid top posting)
Matt Peden wrote:
Javier / All,
I am in the same situation I would like to pass back DataTables, but at
this point I would even settle for DataSet. I cannot figure out the proper
syntax for retrieving the data, as I am always getting the error you
mentioned previously "object named xxxxResult"
Could you post a snip from the DataSet return that was successful? Here is
what I have tried unsuccessfully:
//FacilityInfo2 is the webservice
//FacilityInfo2.get_facilities(); returns a DataSet
DataSet ds = FacilityInfo2.get_facilities();
I have also tried writing this to a Stream and doing a ReadXML to no avail.
It is a bit frustrating because it is so easy to create a working WebService
but there doesn't seem to be any clear examples of how to utilize the data
retrieved from them.
Any ideas would be appreciated?
Matt Peden
"Javier Soques" wrote:
>Most of my clients are .NET, in fact one is a VB6 client and I was able
to convert a DataTable within a DataSet to a classic ADO Recordset and
works perfectly. I come from a DCOM background so passing a .NET object
is not a big fuzz for me. I know for a SOA type web service passing
proprietary objects is no-no, but in my circumstance it's a benefit.
Anyway I wanted to avoid having to pass a DataSet and instead pass a
DataTable since I think is a lighter payload than a DataSet and I will
be using only single tables or joined queries. Funny thing is that with
my VB6 client I can use the web service function that returns a
DataTable but not my 'new' .Net clients.
Thanks anyway.
Javier
John Saunders wrote:
>>"jsoques" <js*****@discussions.microsoft.comwrote in message
news:C0**********************************@micros oft.com...
Hello, I created a Web Service using .Net 2.0 that has a function that
returns a DataTable. I can test the function from the web page when I
access
the .asmx from a browser on localhost and it works. I can also test the
function using VB6 and the xmlhttp activex object. The problem I have now
is
when using VS 2005 or VB.Net 2005 Express and creating a web references is
that the proxy created doesn't map the function as returning a DataTable
instead returns some other type of object named xxxxResult where xxxx is
the
name of the web service function. I have another function that returns a
DataSet that works perfectly with the web reference although I'd rather
use a
DataTable since I won't need all the functionality that a DataSet brings.
Anyone have the same problem and found a solution?
Unless all of the clients of your web service are using .NET, then you
should not be trying to transfer .NET objects to and from your web service.
John
Is your web service consumer a .Net client? If it is it should be
straight forward to consume a DataSet. Your web service function should
return a DataSet. Here is a code snippet (.NET V2) from my web service
function called GetDataset:
******* START WS SNIPPET ******
[WebMethod(BufferResponse = true, Description = "Returns an ADO.Net
DataSet")]
public System.Data.DataSet GetDataset(string sql, string dbalias)
{
System.Data.DataSet DS = null;
String alias = "";
String providerName = "";
String sqldec = System.Web.HttpUtility.UrlDecode(sql);
DS = new System.Data.DataSet();
try
{
alias =
System.Configuration.ConfigurationManager.Connecti onStrings[dbalias].ConnectionString;
providerName =
System.Configuration.ConfigurationManager.Connecti onStrings[dbalias].ProviderName;
}
catch (Exception ex)
{
String[] row = { ex.Message + "\n" + ex.StackTrace };
DataColumn dc = new DataColumn("Error");
DS.Tables.Add();
DS.Tables[0].Columns.Add(dc);
DS.Tables[0].Rows.Add(row);
return DS;
}
try
{
DbProviderFactory provider =
DbProviderFactories.GetFactory(providerName);
DbConnection dbConnection = provider.CreateConnection();
dbConnection.ConnectionString = @alias;
DbCommand objCommand = provider.CreateCommand();
objCommand.Connection = dbConnection;
objCommand.CommandText = sqldec;
objCommand.CommandType = CommandType.Text;
DbDataAdapter objAdapter = provider.CreateDataAdapter();
objAdapter.SelectCommand = objCommand;
dbConnection.Open();
objAdapter.Fill(DS);
objAdapter.FillSchema(DS, SchemaType.Source);
dbConnection.Close();
dbConnection = null;
return DS;
}
catch (DbException ex)
{
String[] row = { ex.Message + "\n" + ex.StackTrace + "\nSQL: " +
sqldec };
DataColumn dc = new DataColumn("Error");
DS.Tables.Add();
DS.Tables[0].Columns.Add(dc);
DS.Tables[0].Rows.Add(row);
return DS;
}
catch (Exception ex2)
{
String[] row = { ex2.Message + "\n" + ex2.StackTrace + "\nSQL: " +
sqldec };
DataColumn dc = new DataColumn("Error");
DS.Tables.Add();
DS.Tables[0].Columns.Add(dc);
DS.Tables[0].Rows.Add(row);
return DS;
}
}
****** END OF WS SNIPPET *******
And here is a snippet of a C# client (created a Web Reference to my
webservice.asmx called MyWebService, a simple form with a button and a
DataGridView):
****** START OF C# WS CONSUMER *****
private void button1_Click(object sender, EventArgs e)
{
MyWebService.jsDataServer jsdata = new MyWebService.jsDataServer();
DataSet ds = new DataSet();
ds = jsdata.GetDataset("SELECT * FROM customers", "northwind2005");
dataGridView1.DataSource = ds.Tables[0];
}
***** END OF C# WS CONSUMER *******
Simple, .Net does everything for you. Also works for .NET v1 clients and
a DataGrid.
Once you get the DataSet object, you should be able to extract data as
any DataSet created.
HTH
Javier