Web Service returning untyped DataSets only; how to get typed data access?

Per Bolmstedt <[email protected]> Tue, 26 Feb 2008 07:25:04 -0500
Newsgroups gmane.comp.windows.devel.dotnet.web
Message-ID <LISTSERV%[email protected]>
(I posted this to a newsgroup[1] this morning, but since I hold the
discuss.develop.com lists in high regard, I thought I'd try here as well.
I've search the list archives and found similar topics come up a few times,
but nothing that helped me.)

I am consuming an ASP.NET Web Service which returns only DataSets for
all operations. The format/schema of the data returned by each method
is known and doesn't change. Untyped DataSets are inelegant to use on
the client when the data format is known, so I want typed data access
to each response type. Using a typed DataSet would be fine, but
anything that programmatically lets me access data is fine.

What is the "Visual Studio" (2005, 2008, doesn't matter) solution to
this? I have attempted to create typed DataSets from the Web Service
using every VS method I could think of, but I haven't gotten it to
work. Things I've tried include

1. xsd.exe /d using actual response XML: the generated .xsd file is
not usable as a typed DataSet as far as I can see.

2. xsd.exe /d using an XSD generated with WriteXmlSchema on the
DataSet returned by the Web Method: same as above.

3. "Create schema" in Visual Studio using actual response XML: I've
found no way to go from here to a typed DataSet.

My current solution is very old-school and relies on XmlSerializer to
deserialize the DataSet/DiffGram XML embedded in the DataSet returned
by the Web Method. This seems to me like a very un-Visual Studio
approach. The only working alternative I have so far is manually
creating typed DataSets, using the Visual Studio designer, to match
the response DataSets. Obviously, this too feels like a suboptimal
approach.

There are numerous references to "Generate DataSet" in the
documentation, but that command is always disabled, regardless of how
I create an XML schema. I'm assuming strict requirements are made on
the XML schema for this to work, but I can't find any information in
the documentation. Maybe it doesn't work the way I imagine it does.
I've also found many references to the drawbacks of using DataSets as
response types in Web Services, but there's nothing I can do about
that.

Any thoughts? All I want is early-bound, typed, programmatic access to
data in the DataSet.

For example, the SOAP response can look like this:

<DataSet>
        <xs:schema id="NewDataSet">
                 (Actual schema here.)
        </xs:schema>
        <diffgr:diffgram>
                <NewDataSet>
                        <MyItem diffgr:id="MyItem1" msdata:rowOrder="0">
                                <MyProperty>1</MyProperty>
                        </MyItem>
                </NewDataSet>
        </diffgr:diffgram>
</DataSet>

(Currently, I am invoking all Web Methods, running the included schemas
through xsd.exe /c, and ultimately deserializing to the generated classes on
the client.)

1:
http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet.webservices/browse_thread/thread/f5dfb0d5bdd79ff6

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com