向WCF服务发送值时,为什么不能将List(Of Integer)类型的值转换为Integer? [英] Why can't value of type List(Of Integer) be converted to Integer when sending value to WCF service?

查看:97
本文介绍了向WCF服务发送值时,为什么不能将List(Of Integer)类型的值转换为Integer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

客户代码:

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

服务代码:

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

推荐答案

DoWork 方法需要一个 Integer(),它是一个整数数组em>.

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

列表(Of T) 类具有名为

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())

有关 MSDN文档

Read more about arrays on the MSDN documentation.

根据此答案,在使用WCF时,将 List(Of T)转换为客户端上的一个数组,这就是为什么 DoWork 方法想要一个数组而不是您指定的 List(Integer)的原因.这种行为显然可以修改.

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.

这篇关于向WCF服务发送值时,为什么不能将List(Of Integer)类型的值转换为Integer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆