Results 1 to 3 of 3

Thread: webservice returning wrong object

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405

    webservice returning wrong object

    please help!

    I have a webservice with a webmethod tat returns a MessageCollection object that contains Message objects. My problem is that when i call the method from a client, i don't get a messagecollection object returned. the return value of the webmethod is a message object (which isn't correct)

    here is the webmethod

    Code:
        <WebMethod()> _
        Public Function GetMessage(ByVal userName As String, ByVal lastMessageID As Integer) As OI.Messages.MessageCollection
            'could check if message needs to be returned by checking lastid passed here.
            'get arraylistlist of groups to message. from most recent message
            'get list of ous from username
            'iterate thru ous from username
            'if arraylist of groups to message contains a ou 
            'and the messageid > lastmessageid then return an arraylist containing
            'messageid, message, sender
            'first off check if there has been a new message
            If Handshake() > lastMessageID Then
                'there has been a more recent message, so go get it
                Dim arrListOfUserOUs As ArrayList
                Dim colMessage As I4M.I4M.its4meOI.Messages.MessageCollection
    
                Dim enMsg As IEnumerator
                Dim en As IEnumerator
                Dim i As Integer
                arrListOfUserOUs = GetOUFromUserName(userName)
                'returns messagecollection of message
                colMessage = GetOUsToMessage(lastMessageID)
                'enumerate
                en = arrListOfUserOUs.GetEnumerator
    
                For i = 0 To colMessage.Count - 1
                    While en.MoveNext
                        If colMessage.Item(i).OUArrayList.Contains(en.Current()) Then
                        Else
                            colMessage.RemoveAt(i)
                        End If
                    End While
                Next
                'ok we have got a list of goodies lets return it to the client.
                Return colMessage
            Else
                Return Nothing
            End If
    
        End Function
    here is the code for the message and messagcollection objects

    Code:
    Imports System
    
    Namespace OI.Messages
    <serializable> _
    Public Class Message
    
    #Region "constructor"
        Public Sub New()
        End Sub
    #End Region
    
    #Region "membervariables"
            Private iMessageID As Integer
            Private dDateSent As Date
            Private sMessageText As String
            Private sSentBy As String
            Private arrOUs As ArrayList
    
    #End Region
    
    #Region "properties"
    
    
            Public Property MessageID() As Integer
                Get
                    Return iMessageID
                End Get
                Set(ByVal Value As Integer)
                    iMessageID = Value
                End Set
            End Property
    
            Public Property DateSent() As Date
                Get
                    Return dDateSent
                End Get
                Set(ByVal Value As Date)
                    dDateSent = Value
                End Set
            End Property
    
            Public Property MessageText() As String
                Get
                    Return sMessageText
                End Get
                Set(ByVal Value As String)
                    sMessageText = Value
                End Set
            End Property
    
            Public Property SentBy() As String
                Get
                    Return sSentBy
                End Get
                Set(ByVal Value As String)
                    sSentBy = Value
                End Set
            End Property
    
            Public ReadOnly Property OUArrayList() As ArrayList
                Get
                    Return arrOUs
                End Get
            End Property
    #End Region
    
            Public Sub SetOUArray(ByVal strOU As String)
                Dim arrOUsPass As New ArrayList(Split(strOU, ","))
                arrOUs = arrouspass
            End Sub
    
    End Class
    End Namespace
    
    '''the message collection object
    
    Imports System
    Imports System.Collections
    
    Namespace OI.Messages
        <Serializable()> _
            Public Class MessageCollection : Inherits CollectionBase
    
    
            Public Overridable ReadOnly Property IsFixed() As Boolean
                Get
                    Return False
                End Get
            End Property
    
            ''' <summary>
            ''' Indicates if the collection is read only.
            ''' </summary>
            Public Overridable ReadOnly Property IsReadOnly() As Boolean
                Get
                    Return False
                End Get
            End Property
    
            Default Public Overridable Property Item(ByVal index As Integer) As OI.Messages.Message
                Get
                    Return CType(Me.List(index), OI.Messages.Message)
                End Get
                Set(ByVal Value As OI.Messages.Message)
                    Me.List(index) = Value
                End Set
            End Property
    
            ''' <summary>
            ''' Returns the index (position) of an item in the collection.
            ''' </summary>
            ''' <param name="item">Item to be searched.</param>
            ''' <returns>Returns the index(position) of the item.</returns>
            Public Overridable Function IndexOf(ByVal item As OI.Messages.Message) As Integer
                Return Me.List.IndexOf(item)
            End Function
    
            ''' <summary>
            ''' This method appends an item to the collection.
            ''' </summary>
            ''' <param name="item">Item to be appended.</param>
            ''' <returns>Returns an integer that indicates if the item was successfully appended.</returns>
            Public Overridable Function Add(ByVal item As OI.Messages.Message) As Integer
                Return Me.List.Add(item)
            End Function
    
            ''' <summary>
            ''' Removes an item from the collection.
            ''' </summary>
            ''' <param name="item">Item to be removed from the collection.</param>
            Public Overridable Sub Remove(ByVal item As OI.Messages.Message)
                Me.List.Remove(item)
            End Sub
    
    
            ''' <summary>
            ''' Copies an array to another.
            ''' </summary>
            ''' <param name="array">Array to be copied.</param>
            ''' <param name="index">Index to begin the copy.</param>
            Public Overridable Sub CopyTo(ByVal array As Array, ByVal index As Integer)
                Me.List.CopyTo(array, index)
            End Sub
    
            ''' <summary>
            ''' This methoid adds one collection to this collection.
            ''' </summary>
            ''' <param name="collection">Collection to be added.</param>
            Public Overridable Sub AddRange(ByVal collection As OI.Messages.MessageCollection)
                Me.InnerList.AddRange(collection)
            End Sub
    
            ''' <summary>
            ''' This methoid adds one collection to this collection.
            ''' </summary>
            ''' <param name="collection">Collection to be added.</param>
            Public Overridable Sub AddRange(ByVal collection As OI.Messages.Message)
                Me.InnerList.AddRange(collection)
            End Sub
    
            ''' <summary>
            ''' This method tells if the collection contains the item.
            ''' </summary>
            ''' <param name="item">Item to be tested.</param>
            ''' <returns>Returns true if the collection contains the item.</returns>
            Public Overridable Function Contains(ByVal item As OI.Messages.Message) As Boolean
                Return Me.List.Contains(item)
            End Function
    
            ''' <summary>
            ''' Inserts an item in the collection.
            ''' </summary>
            ''' <param name="index">Position to be inserted.</param>
            ''' <param name="item">Item to be inserted.</param>
            Public Overridable Sub Insert(ByVal index As Integer, ByVal item As OI.Messages.Message)
                Me.List.Insert(index, item)
            End Sub
        End Class
    End Namespace
    in the client code if i have a line like this which calls the webmethod,
    it says it will return a message object
    Code:
    wsOI.GetMessage(UserName, LastMessageID)
    Last edited by sagey; Jun 10th, 2005 at 08:52 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width