Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you know what type of object you expect you could serialize the List(of Animal) to byte array and the deserialize the object from the byte array instead.</p> <p>I made a small sample, in VB.NET though but I think you can translate it. I created a class which both the web service and the client shares.</p> <p><strong>Client code</strong></p> <pre><code>Imports System.Xml.Serialization Imports SharedLibrary Public Class Form1 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim client As New ServiceReference1.WebServiceSoapClient Dim a As New Animal a.Name = "Pooh" MessageBox.Show(client.SendObject(XmlSerialize(a), ServiceReference1.ObjectT.Animal)) Dim v As New Vehicle v.Name = "Volvo" MessageBox.Show(client.SendObject(XmlSerialize(v), ServiceReference1.ObjectT.Vehicle)) End Sub Public Shared Function XmlSerialize(ByVal serializableObject As Object) As Byte() Dim serializer As XmlSerializer = New XmlSerializer(serializableObject.GetType()) Dim aMemStr As New System.IO.MemoryStream Dim writer As System.Xml.XmlWriter = System.Xml.XmlWriter.Create(aMemStr) serializer.Serialize(writer, serializableObject) writer.Close() aMemStr.Close() Return aMemStr.ToArray() End Function </code></pre> <p><strong>Shared library</strong></p> <pre><code> Public Class ObjectTypes Public Enum ObjectT Animal Vehicle End Enum End Class Public Class Animal Private strName As String Public Property Name As String Get Return strName End Get Set(value As String) strName = value End Set End Property End Class Public Class Vehicle Private strName As String Public Property Name As String Get Return strName End Get Set(value As String) strName = value End Set End Property End Class </code></pre> <p><strong>Web service</strong></p> <pre><code>&lt;WebMethod()&gt; _ Public Function SendObject(bytObject As Byte(), objType As SharedLibrary.ObjectTypes.ObjectT) As String Try Select Case objType Case ObjectTypes.ObjectT.Animal Dim myAnimal As Animal = XmlDeSerialize(bytObject, GetType(Animal)) Return "I received an animal with name: " &amp; myAnimal.Name Case ObjectTypes.ObjectT.Vehicle Dim myVehicle As Vehicle = XmlDeSerialize(bytObject, GetType(Vehicle)) Return "I received a vehicle with name: " &amp; myVehicle.Name End Select Catch ex As Exception Return "Something went wrong: " &amp; ex.Message End Try Return "I did not receive anything :(" End Function Public Shared Function XmlDeSerialize(ByVal xmlbytearr As Byte(), ByVal objectType As Type) As Object Dim serializer As XmlSerializer = New XmlSerializer(objectType) Dim aStream As System.IO.MemoryStream = New System.IO.MemoryStream(xmlbytearr) Return serializer.Deserialize(aStream) End Function </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload