Storing a non serializable object

O

owen79

Hi,

Disappointingly, I think I already know the answer to this question.

I have a C# class which I'm effectively using as a storage area while
I carry out a sequence of Web Method calls on a third party web
service. The class stores the types returned from each call for the
subsequent method call as they are designed to be done sequentially.

I decided as part of my error handling to try and store the storage
object on a failure; this would be in addition to the event log I was
creating along the way. I made the storage object serializable and put
the code in to convert it to a byte[], unfortunately the types
supplied by third party aren't serializable so it won't work.

Can anyone tell me a way to store this object in my MSSQL database for
inspection on error? There are a not insignificant number of values
stored in it, so it'd be nice to do it as a lump.

Thanks in advance

Owen
 
G

Guest

If the types are returned from a webservice they *must* be serializable,
otherwise how would they be sent over the wire as XML in a SOAP Envelope?
Must be something else going on here.
Peter
 
O

owen79

I'm fairly new to Webservices, so can I tell you the situation and see
if that helps any.

I added a Web Reference using the url for the .asmx that has all of
their method. The reference has hundreds of types like
LoginRequestType which is populated with username and password. The
loginRequestType is passed to a LoginResponseType as a constructor and
returns a LoginResponseType.

My storage class has a LoginResponseType property which I store the
response in, when I try to serialize my class, I get an error to the
effect of LoginResponseType could not be serialized.

So that was where I got that the third party types weren't
serializable. Have I totally got the wrong end of the stick.

Owen
 
A

Alberto Poblacion

owen79 said:
Disappointingly, I think I already know the answer to this question.

I have a C# class which I'm effectively using as a storage area while
I carry out a sequence of Web Method calls on a third party web
service. The class stores the types returned from each call for the
subsequent method call as they are designed to be done sequentially.

I decided as part of my error handling to try and store the storage
object on a failure; this would be in addition to the event log I was
creating along the way. I made the storage object serializable and put
the code in to convert it to a byte[], unfortunately the types
supplied by third party aren't serializable so it won't work.

Instead of using a BinaryFormatter, use the XmlSerializer. This one can
serialize a class even if it is not marked as [Serializable], with the
restriction that it will only save the public fields and read-write
properties, and that it requires a default constructor. But the objects you
are using should be adequate for serializing in this way because otherwise
they wouldn't transfer adequately over the web service, so the XmlSerializer
should solve your problem.
 
G

Guest

Your Reference.cs (Reference.vb) class that was created via the Add Web
Reference dialog should contain the proxy versions of the classes that you
want to use. Look in there. These will be eminently serializable, since they
accurately represent what is actually going back over the wire as XML.
Peter
 

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

Top