Custom response from dataset

N

nano2k

Hi
I'm facing a performance issue with my webservice.
I have a webmethod that returns the result of an sql query. I use an
SqlDataAdapter object that fills an DataSet object with my results. My
problem is that I need to alter a bit my results. For each record I
need to append some new data. So, my current implementation builds a
new XmlDocument which will be filled step by step while looping
through dataset rows and appending my custom info. Finally, the xml
document is sent as the response to the calling client application.
The problem is that using this method allows me to append any
information I need, but the cost is sometimes too big (processing
power + memory) because my method practically doubles the memory
needed for the response to be sent: first, the dataset allocates,
let's say, 10MB, then, I reallocate 10MB (plus 1MB of custom data) to
build my custom response. So, at one moment in processing, my method
allocates 20+ MB.
To avoid this, I think the best way is to alter the dataset itself by
attaching new attributes to each element that represents a record.
Is there a way to access and modify this intimate XML representation
of a dataset?

Thanks.
 
J

John Saunders

nano2k said:
Hi
I'm facing a performance issue with my webservice.
I have a webmethod that returns the result of an sql query. I use an
SqlDataAdapter object that fills an DataSet object with my results. My
problem is that I need to alter a bit my results. For each record I
need to append some new data. So, my current implementation builds a
new XmlDocument which will be filled step by step while looping
through dataset rows and appending my custom info. Finally, the xml
document is sent as the response to the calling client application.
The problem is that using this method allows me to append any
information I need, but the cost is sometimes too big (processing
power + memory) because my method practically doubles the memory
needed for the response to be sent: first, the dataset allocates,
let's say, 10MB, then, I reallocate 10MB (plus 1MB of custom data) to
build my custom response. So, at one moment in processing, my method
allocates 20+ MB.
To avoid this, I think the best way is to alter the dataset itself by
attaching new attributes to each element that represents a record.
Is there a way to access and modify this intimate XML representation
of a dataset?

You don't have to get intimate with the DataSet in order to accomplish this.
You can add columns to the dataset. For instance,

ds.Tables[0].Columns.Add("newColumn1", typeof(string));

You can even create expression columns if some of your columns can be
computed from the values of other columns.

John
 
N

nano2k

Thanks for your response.
For some (good) reasons I need to append some extra data to each
column (like: it's type, and some other computed info, but only for
some specific types of columns). I used to use xml attributes to pass
this kind of info, like this:

<punitid shortDescription="buc" type="guid" someData="someDataValue"
etc>65a13829-2fca-4cc6-ab1f-4f979364a6f5</punitid>

Unfortunately, not all data can be added only by adding extra computed
columns to my dataset (well, datatables).
I found out that the easiest way is to use an XmlDataDocument object
and to pass my dataset to it's constructor.
It seems that no significant overhead is generated by this operation.
Then, I'm able to process each row node and to add as many xml
attributes I want by using plain XmlDocument actions.
My only concern is that I read some posts about XmlDataDocument that
report some troubles using this class. Specifically, the class's
performance drops when used intensely (it's also my case). Ok, the
posts were pretty old, but it seems that this issue was reported to
microsoft as a bug.
Does anybody have update info regarding this? Btw: I'm using v1.1.4322
of .net framework.
Thanks.


John Saunders a scris:
nano2k said:
Hi
I'm facing a performance issue with my webservice.
I have a webmethod that returns the result of an sql query. I use an
SqlDataAdapter object that fills an DataSet object with my results. My
problem is that I need to alter a bit my results. For each record I
need to append some new data. So, my current implementation builds a
new XmlDocument which will be filled step by step while looping
through dataset rows and appending my custom info. Finally, the xml
document is sent as the response to the calling client application.
The problem is that using this method allows me to append any
information I need, but the cost is sometimes too big (processing
power + memory) because my method practically doubles the memory
needed for the response to be sent: first, the dataset allocates,
let's say, 10MB, then, I reallocate 10MB (plus 1MB of custom data) to
build my custom response. So, at one moment in processing, my method
allocates 20+ MB.
To avoid this, I think the best way is to alter the dataset itself by
attaching new attributes to each element that represents a record.
Is there a way to access and modify this intimate XML representation
of a dataset?

You don't have to get intimate with the DataSet in order to accomplish this.
You can add columns to the dataset. For instance,

ds.Tables[0].Columns.Add("newColumn1", typeof(string));

You can even create expression columns if some of your columns can be
computed from the values of other columns.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top