473,396 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DataTable returned from a Web Service

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
9 11991
"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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Stephen | last post by:
I am trying to add some code to below to include a datatable and fill the datatable. The reason for doing this is so as I can check to see whether there are any rows returned by the stored...
0
by: Bob Davies | last post by:
Hi I have a webservice that retrieves data from a database, this is then returned to the calling client application built in windows forms within a dataset, however upon attempting to create...
5
by: Jim Murphy | last post by:
In creating a C# web service, I am having trouble returning a DataTable object as the result of a web method. I have no problem returning native types like string or int, but cannot return a .NET...
4
by: Joseph Geretz | last post by:
I don't get it. A DataTable can't be returned, but a DataSet can. Yet a DataSet contains one or more DataTables. So obviously a DataTable must be serializable. So why not just let me return a...
15
by: Joseph Geretz | last post by:
I'm a bit puzzled by the current recommendation not to send Datasets or Datatables between application tiers. http://support.microsoft.com/kb/306134 ...
3
by: szwejk | last post by:
Hi! I want to return DataTable from web service method. This method generate xml with schema and data. Is there any way to retrun more informations about columns? If I want to get maxLength...
5
by: Frank Hauptlorenz | last post by:
Hello, I recognized some days ago, that returning a DataTable blocks my WCF-Service. Is this a known bug? If I add this table to a new DataSet() and return this, it works. Thank you, Frank
0
by: Proogeren | last post by:
I have made a service that sends a datatable with person information to a client. In the forms init event I call the service to retreive all persons from my service and displays them in a...
2
by: Swys | last post by:
Hi all! I am creating a WCF service (my first). I am going to have a variety of clients, one of which is a PHP client. Now, I've already established that I can return a normal string to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.