I'm currently trying to convert my searchList in the web app from a list to an array so that it can be consumed in the web method. Right now, I'm using a web reference which only allows arrays to be passed and returned. I'd like to just simply convert the list to an array, but it looks like that won't work. I've tried looking online but each scenario I've found hasn't been similar enough to where I'm able to solve this. Any idea on the best way to do this?

Web App

Protected Function SearchCustomer()
    Dim searchList As List(Of prxCustomerWebService1.Customer)
    Dim objCustomerWS As New prxCustomerWebService1.CustomerWS

    searchList = Cache("CustomerData")
    'arr = searchList.ToArray
    If (ddlSearchSpecs.Text = "Contains") Then
        searchList = objCustomerWS.GetContains(tbSearch.Text, ddlSearchFields.Text, searchList)
    ElseIf (ddlSearchSpecs.Text = "Starts With") Then
        searchList = objCustomerWS.GetStartsWith(tbSearch.Text, ddlSearchFields.Text, searchList)
    Else
        searchList = objCustomerWS.GetExact(tbSearch.Text, ddlSearchFields.Text, searchList)
    End If
    If searchList.Count = 0 Then
        lMessage.Text = "No Customers Found"
    End If
    Return searchList
End Function

Web Method

<WebMethod(description:="Gets customers that contain a specific value")> _
Public Function GetContains(ByVal sStringContains As String, ByVal sPropertyName As String, ByVal oListOfCustomers List(Of Customer))
    oListOfCustomers()
    Return CustomerFactory.GetContains(sStringContains, sPropertyName, oListOfCustomers)
End Function

Logic

  Public Shared Function GetContains(ByVal sStringContains As String, ByVal sPropertyName As String, ByVal oListOfCustomers As List(Of Customer))
    Dim oCustomerData As New CustomerData
    Dim oNewListOfCustomers As New List(Of Customer)
    Dim iIndex As Integer
    Dim propertyInfo As PropertyInfo

    propertyInfo = GetType(Customer).GetProperty(sPropertyName)

    If IsNothing(oListOfCustomers) = False AndAlso oListOfCustomers.Count > 0 Then
        Try
            For iIndex = 0 To oListOfCustomers.Count - 1
                If (propertyInfo.GetValue(oListOfCustomers.Item(iIndex)).ToString.Trim.ToLower.Contains(sStringContains.ToLower) = True) Then
                    oNewListOfCustomers.Add(oListOfCustomers.Item(iIndex))
                End If
            Next
        Catch ex As Exception
            Return True
        End Try
    End If
    Return oNewListOfCustomers
End Function

Related posts

Recent Viewed