XmlSerializer not serializing Booleans or Integers?


S

SiJP

Hi,

My vb.net project sends an Input object to a webservice and retrieves
a Results object.

The webservice is maintained by a third party, and is pretty huge.

I am using the following procedure to serialize both the input and
result objects to Xml:

Public Function Serialize(Of T)(ByVal obj As T) As String
Try
Dim returnXML As String = String.Empty
Dim serializer As New
Serialization.XmlSerializer(GetType(T))
Using writer As New IO.StringWriter
serializer.Serialize(New XmlTextWriter(writer), obj)
returnXML = writer.ToString()
End Using
Return returnXML
Catch ex As Exception
Msgbox(ex.ToString)
End Try
End Function

The Xml generated from the Results object includes Integers and
Booleans. My problem is the Input object (although is enumerated with
correct values) does not seem to serialize any integers or booleans to
Xml (strings are fine).

Is there anything obvious I should be looking out for?

Thanks
 
Ad

Advertisements

P

Patrice

I would start by doing a simple test on such as class to check if it works
correctly. Hard to say more from the provided info. What is the missing
information (nature and access modifiers i.e. is this a public property or
whatever else ?)

You said "it seems". What makes you thought exactly this is not properly
serialized (have you just saved the corresponding XML so that you can have a
look at it using a text editor) ? (I hardly see how you could get a correct
result if the input send to the service is not correct)

Also as a side note you could perhaps have a proxy created for this web
service in whihc cases serialization would be done through the proxy. Here
it looks like you are sending/retrieving directly the XML content and that
you serialize/deserialize yourself ?
 
A

Alberto Poblacion

SiJP said:
The Xml generated from the Results object includes Integers and
Booleans. My problem is the Input object (although is enumerated with
correct values) does not seem to serialize any integers or booleans to
Xml (strings are fine).

Is there anything obvious I should be looking out for?

Are your integers an booleans marked as "public"? The XmlSerializer does
not serialize private fields. Also, if they are properties, I think I
remember having read that they should be read/write (have a get and a set
accessor) if they are to be serialized by the XmlSerializer.

There is an article on MSDN on Troubleshooting the XmlSerializer:
http://msdn2.microsoft.com/en-us/library/aa302290.aspx
 
Ad

Advertisements


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