473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Best Practices

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>
Nov 6 '06 #1
2 2269
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>

Nov 6 '06 #2
"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?
No.
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)?
What do you expect your clients to do with the schema? Load it into a
DataSet? That might work if they're all .NET clients.
4. For this scenario, is there a preferable return type or will either
DataSet or XmlNode be okay?
It would be preferable if you kept platform-specific data types out of your
web service contract. That way, your web service could be used by any client
you can think of, and many more that you've never heard of, nor ever will
hear of. Instead, define the structure of your data using a schema. Include
that schema in your WSDL. Transform your data into that format however you
like, and return it as an XmlNode (or XmlElement), using the appropriate
attributes to indicate the local name and namespace of the element you're
returning.
John
Nov 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: byrocat | last post by:
I'm chasing after a documetn that was available on one of the Microsoft websites that was titled somethign like "MS SQL Server Best Practices" and detailed a nyumber of best practices about...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
13
by: john doe | last post by:
A quick question, about so-called 'best practices', I'm interested in which of A/B of the two examples people would choose, and why. public enum MyEnum { Option1 = 0, Option2 = 1, Option3 =...
1
by: | last post by:
Hi can someone send or point me to Any nice Material on .NET Best Practices -regards
2
by: Amelyan | last post by:
Could anyone recommend a book (or a web site) that defines best practices in ASP.NET application development? E.g. 1) Precede your control id's with type of control btnSubmit, txtName, etc. 2)...
4
by: Luis Esteban Valencia | last post by:
Hello. Can somebody recomend me books of design patterns in c# and best practices too.
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
0
by: Louis Aslett | last post by:
I hope this is the correct newsgroup for this query (if not please give me a pointer to where is best): I understand the theory of normalisation etc and am trying to follow best practices in the...
10
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable directly or do I use the public property? ...
3
by: John Dalberg | last post by:
I am looking for an ASP.NET application on CodePlex which exemplifies best practices for the following: - Use of interfaces - Seperation of the UI, business and data tiers - Data Tier that uses...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.