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 GetEmployeesResponse GetEmployees()
{
DataSet emps = _db.GetEmployees();
GetEmployeesResponse resp = new GetEmployeesResponse();
emp.Employees = _empMapper.ToEmployeeType(emps);
return resp;
}
On the wire, the GetEmployeesResponse 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***@discussions.microsoft.comwrote in message
news:88**********************************@microsof t.com...
>I have a DataSet with relations and other constraints being populated from
the backend (SQL Server 2005). I use DataSet.FillSchema 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="PersonDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="PersonDataSet" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Entity">
<xs:complexType>
<xs:sequence>
<xs:element name="EntityID" msdata:ReadOnly="true"
msdata:AutoIncrement="true" msdata:AutoIncrementSeed="-1"
msdata:AutoIncrementStep="-1" type="xs:int" />
<xs:element name="EntityTypeID" type="xs:int" minOccurs="0"
/>
<xs:element name="ParentEntityID" type="xs:int"
minOccurs="0" />
<xs:element name="EntityStatusID" type="xs:int"
minOccurs="0" />
<xs:element name="UpdatedByID" type="xs:int" />
<xs:element name="UpdatedDate" type="xs:dateTime" />
<xs:element name="RecordIsActive" type="xs:boolean"
default="true" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Person">
<xs:complexType>
<xs:sequence>
.
.
.
.
.
<xs:unique name="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//Entity" />
<xs:field xpath="EntityID" />
</xs:unique>
<xs:unique name="Person_Constraint1"
msdata:ConstraintName="Constraint1" msdata:PrimaryKey="true">
<xs:selector xpath=".//Person" />
<xs:field xpath="PersonID" />
</xs:unique>
.
.
.
.
.
.
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<PersonDataSet xmlns="">
<Entity diffgr:id="Entity1" msdata:rowOrder="0">
<EntityID>10000</EntityID>
<EntityTypeID>1000</EntityTypeID>
<UpdatedByID>22222</UpdatedByID>
<UpdatedDate>2006-11-02T07:54:45.873-06:00</UpdatedDate>
<RecordIsActive>true</RecordIsActive>
</Entity>