Search code examples
asp.netvb.netweb-serviceswcfwcf-data-services

Why can't value of type List(Of Integer) be converted to Integer when sending value to WCF service?


Client code:

Public Sub sendEmpValue(name As String, value As List(Of Integer))
    Dim serviceObject As New Service.GetEmployeeClient
    serviceObject.DoWork(name, value)** getting error at the value**
End Sub

Service code:

Sub DoWork(name As String, value As List(Of Integer)) Implements IGetEmployee.DoWork
End Sub

screenshot of the error


Solution

  • The DoWork method expects an Integer() which is an array of integers.

    The List(Of T) class has got a function called ToArray() which will return the list as an array. Call that and it should work.

    serviceObject.DoWork(name, value.ToArray())
    

    Read more about arrays on the MSDN documentation.


    According to this answer when using WCF a List(Of T) is converted into an array on the clientside, which is why the DoWork method wants an array instead of a List(Of Integer) as you've specified. This behaviour can apparently be modified though.