VB.NET中的WCF - 函数尝试返回Array时出错

时间:2016-03-18 20:59:35

标签: vb.net wcf

我在VB.NET中设置了一个WCF,我试图让一个函数返回一个数组。 这样做不对!我尝试了很多东西并且搜索了很多东西。

所以错误是:

enter image description here

我在WCF中的功能:

    Public Function GetCL_Contacts(ByVal cl_ID As Integer) As String() Implements SQLOperator.GetCL_Contacts
    Dim Contacts() As String
    Contacts = {}
    Try
        SQLCon.ConnectionString = SQLConString
        SQLCon.Open()

        SQLCMD = New SqlCommand("Select Nome from dbo.cl_contact Where cl_ID=" & cl_ID & " ORDER BY ID ASC;", SQLCon)
        SQLDataReader = SQLCMD.ExecuteReader()

        Dim I As Integer = 0
        While SQLDataReader.Read
            Contacts(I) = SQLDataReader("Nome")
            I = I + 1
        End While

    Catch ex As Exception
        MsgBox("Erro: " & Environment.NewLine & ex.ToString)
    Finally
        SQLCon.Close()
        SQLCon.Dispose()
    End Try

    Return Contacts
End Function

我如何尝试使用该功能:

    'Load Contacts
    Dim Contacts() As String
    Contacts = {}
    Contacts = Service.GetCL_Contacts(clBox.SelectedIndex + 1)
    For Each contact As String In Contacts
        BoxCl_Contacts.Items.Add(contact)
    Next

我是如何尝试解决此问题(并完全失败):

  • 我被绑定以声明这样的联系人:Dim Contacts(100)As String
  • 另一个声明:Dim Contacts(0到100)As String

以上都没有奏效!

0 个答案:

没有答案