Return Strongly Typed Data Set from Web Service

H

HardBap

I've created a strongly typed DataSet (Customers.xsd) using the xsd.exe
tool. I want to be able to access fields using
ds.Customer[0].CompanyName.

The problem is when I return this DataSet from a Web Service it adds
another Table to the DataSet that contains the data. I have to access
the data using ds.Tables[1].Rows[0]["CompanyName"].ToString(). This
defeats the whole purpose of using a strongly typed DataSet.

Thanks in advance for the help.
 
M

Michael Rodriguez

HardBap said:
I've created a strongly typed DataSet (Customers.xsd) using the xsd.exe
tool. I want to be able to access fields using
ds.Customer[0].CompanyName.

The problem is when I return this DataSet from a Web Service it adds
another Table to the DataSet that contains the data. I have to access
the data using ds.Tables[1].Rows[0]["CompanyName"].ToString(). This
defeats the whole purpose of using a strongly typed DataSet.

Thanks in advance for the help.

I would advise against that approach. The web service proxy has trouble
with custom data types, which is what your strongly typed dataset really is.
You can make it work, but you have to remember to edit the proxy every time
you update your web service reference.

What I wound up doing, and it works very well, is to return generic datasets
from the web service. That way you never have to manually edit the proxy
class. Then, in my business logic layer, I load the generic dataset into a
strongly typed dataset that is then ready for binding, manipulating, etc.
It loads really fast, just use this command:

// load the generic data from the data layer into a strongly typed dataset
dsStronglyTyped.Load(dsGeneric.Tables[0].CreateDataReader(),
LoadOption.OverwriteChanges,
dsStronglyTyped.mytablename);

HTH,

Mike Rodriguez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top