I think the manner in which you populate a dataset is irrelevant - that is
the service consumer is only concerned with "how" to get data from the
webservice, and not so much how the service will go about fullfilling that
request.
That being said, there's debate over the "return dataset from webservice"
topic -
http://www.theserverside.net/tt/arti...Top5WSMistakes
I think the notion of a WebMethod signature with a DataSet as a return type
does little to offer semantic meaning to the service. That is, I believe the
following:
[WebMethod]
public DataSet GetEmployees(){ }
is semantically different than:
[WebMethod]
public GetEmployeesRes ponse GetEmployees()
{
DataSet emps = _db.GetEmployee s();
GetEmployeesRes ponse resp = new GetEmployeesRes ponse();
emp.Employees = _empMapper.ToEm ployeeType(emps );
return resp;
}
On the wire, the GetEmployeesRes ponse message is self describing versus a
message containing an array of Employee objects.
Here is some more opinion on the subject:
http://www.lhotka.net/WeBlog/Thought...bServices.aspx
Code to map a dataset to a "message" is not a whole lot of fun to write,
even for a single-tabled dataset it can be tedious.
If you can consider a redesign of the service, the following might be
useful.
http://www.thinktecture.com/Resource...kthrough1.html
There you can download the WSCF tool and the walkthrough is an excellent
starting point for getting into "contract-first" development of web
services.
Ron
"Eddie" <Ed***@discussi ons.microsoft.c omwrote in message
news:88******** *************** ***********@mic rosoft.com...
>I have a DataSet with relations and other constraints being populated from
the backend (SQL Server 2005). I use DataSet.FillSch ema to retrieve the
table schema for each table in the dataset. I then create the appropriate
relations between the tables. I will use a webmethod with a return type
of
either XmlNode or DataSet to return the data and the schema? Each call to
the webmethod will return the data and the schema.
Question:
1. Does this scheme seem to follow best practices?
2. The data, the table schema and the relations are all defined via 1
method. Should this be broken up into 2 methods? GetSchema() &
GetData(int
ID).
3. Is there an advantage to wrapping the data in a mapped class and then
serializing the class or does providing the dataset schema accomplish the
same thing thing (typed data)?
4. For this scenario, is there a preferable return type or will either
DataSet or XmlNode be okay?
Sample xml returned from Webmothod:
<?xml version="1.0" encoding="utf-8"?>
<DataSet xmlns="http://www.somedataset .com/ws/test.xml">
<xs:schema id="PersonDataS et" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata">
<xs:element name="PersonDat aSet" msdata:IsDataSe t="true"
msdata:UseCurre ntLocale="true" >
<xs:complexType >
<xs:choice minOccurs="0" maxOccurs="unbo unded">
<xs:element name="Entity">
<xs:complexType >
<xs:sequence>
<xs:element name="EntityID" msdata:ReadOnly ="true"
msdata:AutoIncr ement="true" msdata:AutoIncr ementSeed="-1"
msdata:AutoIncr ementStep="-1" type="xs:int" />
<xs:element name="EntityTyp eID" type="xs:int" minOccurs="0"
/>
<xs:element name="ParentEnt ityID" type="xs:int"
minOccurs="0" />
<xs:element name="EntitySta tusID" type="xs:int"
minOccurs="0" />
<xs:element name="UpdatedBy ID" type="xs:int" />
<xs:element name="UpdatedDa te" type="xs:dateTi me" />
<xs:element name="RecordIsA ctive" type="xs:boolea n"
default="true" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Person">
<xs:complexType >
<xs:sequence>
.
.
.
.
.
<xs:unique name="Constrain t1" msdata:PrimaryK ey="true">
<xs:selector xpath=".//Entity" />
<xs:field xpath="EntityID " />
</xs:unique>
<xs:unique name="Person_Co nstraint1"
msdata:Constrai ntName="Constra int1" msdata:PrimaryK ey="true">
<xs:selector xpath=".//Person" />
<xs:field xpath="PersonID " />
</xs:unique>
.
.
.
.
.
.
<diffgr:diffgra m xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="u rn:schemas-microsoft-com:xml-diffgram-v1">
<PersonDataSe t xmlns="">
<Entity diffgr:id="Enti ty1" msdata:rowOrder ="0">
<EntityID>10000 </EntityID>
<EntityTypeID>1 000</EntityTypeID>
<UpdatedByID>22 222</UpdatedByID>
<UpdatedDate>20 06-11-02T07:54:45.873-06:00</UpdatedDate>
<RecordIsActive >true</RecordIsActive>
</Entity>