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

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 05:43:09

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/40692142/why-cant-value-of-type-listof-integer-be-converted-to-integer-when-sending-va

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!