Serialize DataSet

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I'm having trouble finding a code example to do the following:

Serialize a dataset into a variable
Deserialize this serialized variable.

All code examples I've seen are writing data to files assuming that everyone
wants to persist the data in a file. I want to skip the saving to file
process and simple hold the serialized data in a variable that can be passed
to a web service. Likewise, I'll want to do the reverse process with out
any reference to a file.

Here's an MSDN article which serializes a dataset using a file:
http://msdn.microsoft.com/library/d...xampleofxmlserializationwithxmlserializer.asp

Can someone help me here?
 
Thanks. So does this mean that there's absolutely no way to do this with
out writing/reading from a file?

--
(e-mail address removed)
William Ryan eMVP said:
You can serialize and deserialize it to a file(which you don't want) a
stream object or a XMLStream

Check out the MSDN Documentation
http://msdn.microsoft.com/library/d.../frlrfsystemdatadatasetclasswritexmltopic.asp
moondaddy said:
I'm having trouble finding a code example to do the following:

Serialize a dataset into a variable
Deserialize this serialized variable.

All code examples I've seen are writing data to files assuming that everyone
wants to persist the data in a file. I want to skip the saving to file
process and simple hold the serialized data in a variable that can be passed
to a web service. Likewise, I'll want to do the reverse process with out
any reference to a file.

Here's an MSDN article which serializes a dataset using a file:
http://msdn.microsoft.com/library/d...xampleofxmlserializationwithxmlserializer.asp
 
Hi,

Thanks for posting in the community.

I am somewhat confusion about why you do not pass the dataset to the
webservices directly, do you have any concern of that?
.NET will serialize the dataset including its schema and data into xml
format and pass to the webservice.

Or I think you may try to serialize the dataset into a memory stream and
retrieve the underlying bytearray, and then pass the byte array to the
webservice.

The link will show how to serialize the dataset into a memory stream.

http://groups.google.com/groups?q=memorystream+dataset+"peter+huang"&hl=
zh-CN&lr=&ie=UTF-8&oe=UTF-8&selm=x3XQ0KU8DHA.1152%40cpmsftngxa07.phx.gbl&rnu
m=1

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks Peter. I want to serialize it first because I'm going to encrypt it
before sending it. In most cases I don't need to do this, but this
particular dataset is sensitive data.
 
Hi,

Thanks for posting in the community.

Have you tried my suggestion that to serialize the dataset into a memory
stream and then do your encrypt stuff to the byte array and then pass to
the webservice.

For the Dataset there is a WriteXml method which can be used to serialize
the dataset into a stream directly, it can be a memory stream too.

If you still have any concern on this issue, please feel free to let me
know.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks Peter. I haven't tried that sample yet, but started working on
something similar on my own using memory streams, but then got derailed in
trying to get the encryption working correctly (getting too many variables
in the mix... no pun intended). My problem now is that I'm trying to
encrypt and decrypt the data while using the key as the same constant on
both sides. It was working at first, but now when I decrypt it, I get an
error saying that the data is the wrong size. Same code worked earlier
today and its now tomorrow. I don't know if datatime has anything to do
with how keys work. Anyway this problem is quite abit different from where
we started. Do you have any code examples of encrypting/decrypting while
persisting the secret key over a long period of time or even just hard
coding it? It seems like this should be simple, but its being a bear for
me.

Thanks.
 
Use the Dataset.GetXML() method. It's probably what your looking for with
Serailzation, then you have a string that you can do whatever you want.
Serialization is used for object persistance across programming boundries
(like remoting, or web services).

HTH,
CJ
 
Thanks that sounds like what I'm looking for. Now is there an easy way to
do the reverse process of taking that string and converting it back to a
dataset without first writing it to a file and then generating a dataset
based on that file?
 
Hi,

I have posted a reply in the group below.

Subject: RE: Problem sending encrypted data via webservice
Newsgroups: microsoft.public.dotnet.languages.vb

You may go and take a look.
If you have any concern, please reply in that thread.

Thanks!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top