By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 783 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

DataTable returned from a Web Service

P: n/a
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?

Appreciate any help, thanks
Javier
Sep 23 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
"jsoques" <js*****@discussions.microsoft.comwrote in message
news:C0**********************************@microsof t.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
Sep 24 '06 #2

P: n/a
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**********************************@microsof t.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

Sep 25 '06 #3

P: n/a
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**********************************@microsof t.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
Sep 26 '06 #4

P: n/a
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
Sep 27 '06 #5

P: n/a
Answer/Comments at the end. (Sorry about previous top posting)

"Javier Soques" wrote:
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**********************************@microso ft.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
Javier,

Thanks for the reply and snippets. Based on further thread reviews and
project analysis. i ended up movign to outputting XMLDocument object in order
to ease the flow of data and ensure a non-platform specific output from the
webservice. I have this functionality working now and appears solid. This
methodology will also ensure that if we implement a component that cannot
handle DataSets then we won't be stuck out in the cold and have to re-create
the wheel.

Matt
Sep 28 '06 #6

P: n/a
Matt Peden wrote:
Answer/Comments at the end. (Sorry about previous top posting)

"Javier Soques" wrote:
>>...........................................
Javier,

Thanks for the reply and snippets. Based on further thread reviews and
project analysis. i ended up movign to outputting XMLDocument object in order
to ease the flow of data and ensure a non-platform specific output from the
webservice. I have this functionality working now and appears solid. This
methodology will also ensure that if we implement a component that cannot
handle DataSets then we won't be stuck out in the cold and have to re-create
the wheel.

Matt
Valid, that's what web service are for. I'm really using Datasets with
..Net web service as a replacement for DCOM.

Javier
Sep 28 '06 #7

P: n/a
Based on Javier's original post, the actual original problem was
identified and never really solved but was "worked around". I have this
problem and would love to solve it :-). Javier says:

"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."

My own box has both 2003 and 2005 on it and I am guessing this has
something to do with the Visual Studio 2005 IDE referencing an ealier
version of the tool that generates the web service proxy classes when I
attempt to add a web reference that contains a DataTable . Since the
older version would not recognize DataTables, it instead uses a type
called 'xxxxResult'.

If you go into the proxy classes and manipulate them to change the
datatype on the method to DataTable, all is well. But this goes out the
window when the ref is updated.

But how does one get 2005 to use the correct proxy generator? I have
looked everywhere in the VS config files, the registry, etc. as well as
googling everywhere and I cannot seem to get a bead on this problem.
What is encouraging is that I am not, based on the evidence of Javier's
post, the only one.

Any ideas would be appreciated.

TS Good

*** Sent via Developersdex http://www.developersdex.com ***
Oct 5 '06 #8

P: n/a
Do we have any resolution on this? I'm about to give ino the fact that I
simply must use DataSets instead of DataTables. Seems like a waste to
introduce uneeded overhead...

"tsgood" wrote:
Based on Javier's original post, the actual original problem was
identified and never really solved but was "worked around". I have this
problem and would love to solve it :-). Javier says:

"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."

My own box has both 2003 and 2005 on it and I am guessing this has
something to do with the Visual Studio 2005 IDE referencing an ealier
version of the tool that generates the web service proxy classes when I
attempt to add a web reference that contains a DataTable . Since the
older version would not recognize DataTables, it instead uses a type
called 'xxxxResult'.

If you go into the proxy classes and manipulate them to change the
datatype on the method to DataTable, all is well. But this goes out the
window when the ref is updated.

But how does one get 2005 to use the correct proxy generator? I have
looked everywhere in the VS config files, the registry, etc. as well as
googling everywhere and I cannot seem to get a bead on this problem.
What is encouraging is that I am not, based on the evidence of Javier's
post, the only one.

Any ideas would be appreciated.

TS Good

*** Sent via Developersdex http://www.developersdex.com ***
Mar 19 '07 #9

P: n/a
No, it is not possible to return a DataTable from a web service. You will
need to wrap it inside a DataSet.
Jul 23 '08 #10

This discussion thread is closed

Replies have been disabled for this discussion.