Web Method return a complex class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeytu
    New Member
    • Jul 2006
    • 2

    #1

    Web Method return a complex class

    Hi all,
    I'm a newbie with .net. I have created a web method that would return a class.
    The definition of the class is
    <Serializable() > Public Class Response
    Dim l_status As Boolean
    Dim l_Message As New ArrayList
    Public Property Status() As Boolean
    Get
    Status = l_status
    End Get
    Set(ByVal Value As Boolean)
    l_status = Value
    End Set
    End Property
    Public Property Messages() As ArrayList
    Get
    Messages = l_Message
    End Get
    Set(ByVal Value As ArrayList)
    l_Message = Value
    End Set
    End Property
    Dim lbooks As New Books
    Public Property mybooks() As Books
    Get
    mybooks = lbooks
    End Get
    Set(ByVal Value As Books)
    lbooks = Value
    End Set
    End Property
    End Class

    Wherein Books is a collection of class Book.

    When invoking the webmethod that returns the Response class, I get a "System.Invalid OperationExcept ion: Request format is unrecognized" error, if the class Response has some value for Books. But if it is just an Arraylist, it's okay.
    Would somebody help me, what is wrong with my class definition? Thanks.

    <Serializable() > _
    Public Class Book
    Private mName As String
    Public Sub New(ByVal bookName As String)
    mName = bookName
    End Sub

    Public Property Name() As String
    Get
    Return mName
    End Get
    Set(ByVal Value As String)
    mName = Value
    End Set
    End Property
    End Class

    <Serializable() > _
    Public Class Books
    Implements IEnumerable
    Private mList As New ArrayList

    Public Sub Add(ByVal bk As System.Object)
    bk = DirectCast(bk, Book)
    mList.Add(bk)
    End Sub

    Default Public ReadOnly Property List(ByVal index As Integer) As Book
    Get
    Return DirectCast(mLis t(index), Book)
    End Get
    End Property

    Public Function GetEnumerator() As System.Collecti ons.IEnumerator Implements System.Collecti ons.IEnumerable .GetEnumerator
    Return New BooksEnumerator (mList)
    End Function

    Class BooksEnumerator
    Implements IEnumerator
    Private index As Integer = -1
    Private mList As ArrayList

    Friend Sub New(ByVal list As ArrayList)
    mList = list
    End Sub
    Public ReadOnly Property Current() As Object Implements System.Collecti ons.IEnumerator .Current
    Get
    Return mList(index)
    End Get
    End Property
    Public Function MoveNext() As Boolean Implements System.Collecti ons.IEnumerator .MoveNext
    If index < mList.Count - 1 Then
    index += 1
    Return True
    Else
    Return False
    End If
    End Function
    Public Sub Reset() Implements System.Collecti ons.IEnumerator .Reset
    index = 0
    End Sub
    End Class
    End Class
Working...