all groups > dotnet web services > march 2006 >
You're in the

dotnet web services

group:

Generic WebService


Re: Generic WebService Josh Twist
3/9/2006 2:25:01 PM
dotnet web services: Hi Bala,

There's other reasons why returning a DataSet from a web service is bad
- I think Scott Hanselman puts it very well in this article where he
compares a dataset to a fruitbowl when what you really should be
returning is the fruit:
http://www.hanselman.com/blog/ReturningDataSetsFromWebServicesIsTheSpawnOfSatanAndRepresentsAllThatIsTrulyEvilInTheWorld.aspx

So you want a .NET object that represents the data item that you return
from your webservice... let's pretend it's all the cars in your
showroom - your code may look something like this (note, this sample
uses .NET 2.0 generic collections but the same can be achieved in .NET
1.x).

using System.Collection.ObjectModel;

[WebMethod]
public ShowRoom GetShowRoom()
{
// call into a business component that calls the DAL and populates
a ShowRoom object with
// with all the cars from the DB. Simply loop through the
datareader [or dataset :( ] and create
// the objects as you go.
}

[XmlRoot("showRoom")]
public class ShowRoom
{
[XmlArray("cars"), XmlArrayItem("car")]
public Collection<Car> Cars;
}

public class Car
{
[XmlElement("manufacturer")]
public string Manufacturer;

[XmlElement("engineSize")]
public int EngineSize;

[XmlElement("color")]
public string Color;

// ... you get the idea!
}

This will generate a beautiful WSDL that will interoperate well and
generate an intuitive schema.

Finally, you could try dropping the DataSet approach and use a quick
forward-only datareader to generate your domain objects - here's a
great article on 4guys about DataSets vs DataReaders in ASP.NET:
http://aspnet.4guysfromrolla.com/articles/050405-1.aspx

Hope that all helps

Josh
http://www.thejoyofcode.com/
Generic WebService Bala Nagarajan
3/9/2006 3:07:50 PM
Hello,
I am working with a webservice developed by my team some time back
and found a problem with it. All the web service methods returned a dataset
instead of a more generic object . Clearly this is not the best way to
develop a web service because it is so tightly coupled that only .NET
clients can use it. The dataset returned by the web service has 1000's of
records in it.

My question is how can i map the records in dataset so it to a generic
object so that it can be used by non .NET clients? Obviously i do not want
instantiate a generic object for each of the record in the dataset and
return an array of those objects to the client as this can be a very
resource intensive process. Any thoughs on how efiecently this can be done?

Thanks
Bala

Re: Generic WebService stcheng NO[at]SPAM online.microsoft.com
3/10/2006 12:00:00 AM
Thanks Josh's informative inputs,

Hi Bala,

For DataSet object, it is transferred as its XML content, so other non-
..NET client can just parse the raw XML content directly. Also, to make the
element be better understandable by different client consumers( to generate
their proxies), you can consider defining the return type as XmlDocument
and return the DataSet's XML content at runtime instead of directly return
the DataSet instance.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
AddThis Social Bookmark Button