Webservice with Multiple Functions and Custom Types not Working

I have a webservice that has two functions that both return a custom type.   If I comment out either function, the webservice works as expected, but if both functions are compliled the first function works fine, but the second gives this error.

System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidCastException: Unable to cast object of type ItemsOnInvoiceCollection; to type ;BusinessLogic.PartTypeCollection;.

He is the simplified code.

<XmlInclude(GetType(BusinessLogic.PartTypeCollection)), XmlInclude(GetType(BusinessLogic.PartType)), XmlInclude(GetType(BusinessLogic.Types.ItemsOnInvoiceCollection)), XmlInclude(GetType(BusinessLogic.Types.ItemsOnInvoice))> _
<WebService(Namespace:="")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class ScannerFunctions
    Inherits System.Web.Services.WebService

 <WebMethod(), XmlInclude(GetType(BusinessLogic.PartTypeCollection)), XmlInclude(GetType(BusinessLogic.PartType))>
    Public Function GetGroupedPartData(ByVal GNumber As String, ByVal UserID As String) As BusinessLogic.PartTypeCollection
        Dim oEmployee As New Employee(Guid.Parse(UserID))
        If oEmployee.HasValue Then
            Dim oScannerHandler As New BusinessLogic.ScannerHandler()
            Dim parts As New PartTypeCollection
            Dim Info As String = ""
            For Each Part As PartType In parts
                If oScannerHandler.GetCurrent_DT_WO_INV_PO_AND_ROUTE_ByRNumber(Part.InventoryID, Info, True) Then
                    Part.extraInfo1 = Info
                End If
            Return parts
            Return Nothing
        End If

  <WebMethod(), XmlInclude(GetType(BusinessLogic.Types.ItemsOnInvoiceCollection)), XmlInclude(GetType(BusinessLogic.Types.ItemsOnInvoice))>
    Public Function GetItemsOnDTOrInvoice(ByVal Number As Integer, ByVal IsADeliveryTicket As Boolean) As BusinessLogic.Types.ItemsOnInvoiceCollection
        Dim objReturn As New BusinessLogic.Types.ItemsOnInvoiceCollection
        If IsADeliveryTicket Then
        End If
        Return objReturn

    End Function

Open in new window

Who is Participating?
Miguel OzConnect With a Mentor Software EngineerCommented:
The methods seems alright but I think you are missing :
End Function
on your first function,(add it at line 25)
pamsautoAuthor Commented:
Sorry, that is just a cut a paste error.  In the executing code has the End Function in it.
pamsautoAuthor Commented:
Was not the solution, but I figured out the issue off site
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.