Serializing Object Model

D

Dave T

I have a generic.list(of T) class that has a property of another class type
that I want to return form a web service. Everything gets populated OK but
when I serialize, the property is left out. Any ideas?


Below, the property in question is "UserInputAddress". In the web service,
just before the serialization, I am able to address the property and it's
components have values.

Namespace DataStructure
<System.Xml.Serialization.XmlRoot("Addresses")> _
<Serializable()> _
Public Class Addresses
Inherits System.Collections.Generic.List(Of Address)

....

Private _UserInputAddress As New SearchInput
Public Property UserInputAddress() As SearchInput
Get
Return _UserInputAddress
End Get
Set(ByVal value As SearchInput)
_UserInputAddress = value
End Set
End Property

....

End Class
End Namespace

Namespace DataStructure
<Serializable()> _
Public Class Address

.... A bunch of properties...

End Class
End Namespace

<WebMethod()> _
Public Function SearchByCountyStreet(ByVal County As String, ByVal
Street As String) As System.Xml.XmlDocument
Dim _XML As New System.Xml.XmlDocument
Dim _Addresses As New DataStructure.Addresses
Dim _Serializer As New
System.Xml.Serialization.XmlSerializer(GetType(DataStructure.Addresses))
Dim _Writer As New System.IO.StringWriter
_Addresses.UserInputAddress.Jurisdiction = County
_Addresses.UserInputAddress.StreetName = Street
_Addresses.GetAddressesByCountyStreet()
_Serializer.Serialize(_Writer, _Addresses)
_XML.LoadXml(_Writer.ToString)
Return _XML
End Function


XML(I want to see a "UserInputAddress" element)

<?xml version="1.0" encoding="utf-8"?>
<Addresses xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Address>
<Number>123</Number>
<Street>this</Street>
</Address>
<Address>
<Number>345</Number>
<Street>that</Street>
</Address>
</Addresses>
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top