views:

390

answers:

2

I have a webservice method defined as so:

[WebMethod]
public DataTable GetResponseCodeTypes()
{
  // connect to database and retrieve results,
  // then populate and return a DataTable
}

The method has been verified via the webservice test form and returns a DataTable as expected:

<?xml version="1.0" encoding="utf-8"?>
<DataTable xmlns="http://tempuri.org/"&gt;
  <DocumentElement xmlns="">
    <ResponseCodeTypes>
      <CodeTypeId>1</CodeTypeId>
      <Descrip>RPC</Descrip>
    </ResponseCodeTypes>
    <ResponseCodeTypes>
      <CodeTypeId>2</CodeTypeId>
      <Descrip>Non-RPC</Descrip>
    </ResponseCodeTypes>
    <ResponseCodeTypes>
      <CodeTypeId>3</CodeTypeId>
      <Descrip>No connect</Descrip>
    </ResponseCodeTypes>
  </DocumentElement>
</DataTable>

However, when I call the GetResponseCodeTypes method from my C# frontend code, not only does it return a DataSet instead of a DataTable, but the returned DataSet contains zero tables.

I then went and modified the stub class (generated by Visual Studio when a web reference is added) to return a DataTable instead. This works, inasmuch as I do get a DataTable back - but said DataTable has no columns or rows defined.

I know in .NET 1.x it was not possible to return a DataTable from a webservice method (you had to wrap it in a DataSet) but I was under the impression that this was fixed in .NET 2.x...

What is the issue here?

EDIT:

The webservice is .NET 2.0, running on a Linux box under Mono 2.4.2.3; while the frontend code is being developed in .NET 2.0 on a Windows XP machine running VS2008 with SP1.

A: 

As per this link DataTable and Webservice in ADO.NET 2.0

Please note that DataTable itself supports Web-Services, the only thing that's broken is the proxy-generation, once the proxy is created, at runtime, a DataTable instance can be passed around using WebServices.

For the interim period, you may choose any of the following workarounds:

A) Manually create the client side proxy class for each WebService that uses DataTable

B)

  1. compile and GAC the attached SchemaImporterExtension file.
  2. add it to the existent extensions in machine.config, using fully-qualified assembly name

  3. Use the standard mechanisms (like xsd.exe or Visual Studio) to generate the client-side proxy class

Ramesh Vel
Thanks Ramesh - I tried that but it didn't make any difference to the proxy class generated by VS/wsdl.exe. I edited my original post with some more information, could it be Mono causing the problem?
Ian Kemp
ah sorry Kemp.. i am not sure abt the MONO..
Ramesh Vel
A: 

In general, you should not return DataTable, DataSet, or any other type that is specific to .NET. Naturally, they will only work with .NET clients.

John Saunders
That's not a problem because I know for a fact that the webservice will never be consumed by anything other than .NET.
Ian Kemp