473,387 Members | 1,516 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,387 software developers and data experts.

Generic WebService

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
Mar 9 '06 #1
2 2620
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/Return...nTheWorld.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/

Mar 9 '06 #2
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
rights.)

Mar 10 '06 #3

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

Similar topics

6
by: Davie | last post by:
I want to authorise a user of a web service by using the AuthHeaderValue for some reason I keep getting a null reference exception when I try to run the following code: It seems to work fine on a...
0
by: Pablo Gutierrez | last post by:
Hello, I'd like someone tell me the best form of doing this: I am programming a generic report aspx page that will read one of several configuration xml files according to a parameter passed...
1
by: Nalaka | last post by:
Hi, I am testing with Visual studio 2005, web projects. Situation: I have one solution with two web projects, created as file system projects. (I am tesing using the built in server, not IIS)...
0
by: Joris de Gruyter | last post by:
I am trying to find an application -or the info do make one myself- to call any webservice from my PocketPC. We are currently testing some webservices, but it is a pain to have a hardcoded .NET...
4
by: Jonas Hei | last post by:
I've noticed that one can use IE to test web pages (by going on http://hostname/blah/blah.asmx - and then it shows a list of methods supported by the webservice, and on selecting each method once...
7
by: Nalaka | last post by:
Hi, I created a sinple web service that returns a dataSet. Then I created a client program that uses this web service (that returns the Dataset). My question is, how did the client figure...
5
by: AliR | last post by:
Hi Everyone, I have a Visual C++ MFC program, and I am trying to use a webservice written in C#. When I add the webservice to my project using Add Web Reference the sproxy compiler complains...
4
by: mojeza | last post by:
I would like to create generic object which will be used for store of single row of DataTable. Lets say I create class as follow: Public Class Participant Public ParticipantID As Int64 Public...
2
by: Chris Kennedy | last post by:
I am getting a generic list of objects from a webservice. The list is converted to an array by this process. How do I convert the array back to a list and is there any way of finding an object...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.