【发布时间】:2010-08-10 11:53:47
【问题描述】:
我有一个配对列表(CarType(Enum)、code(string))。不幸的是,在这个集合中代码不是唯一的。
Van,C1
Van,C2
Pickup,C1
如何通过 asmx webservice 传递这个集合。
现在我将 KeyValuePair[] 作为 webMethod 中的参数
[webmethod]
public void DestroyCars(KeyValuePair<string, CarType>[] cars)
{
//implementation.
}
但是当我更新我的 webreference(不是 servicereference)并将 KeyValuePair[] 的实例放入
service.DestroyCars(someinstance of KeyValuePair<string, CarType>[])
我得到异常,因为我必须有 KeyPairValuOfStringCarType。
为什么会这样以及如何解决?
为了更清楚:
我想通过webservice传递多维集合。
我创造
[网络方法] 公共无效 DestroyCars(KeyValuePair[] 汽车) { //执行。 }
我更新了我的应用程序的网络参考。
当我想使用 KeyValuePair[] 的新实例从我的应用程序中调用此 webmethod 时,我收到错误消息,指出此参数不可分配给我的 webmethod 的参数类型。
Intellisense 告诉我这个参数的类型是 KeyPairValuOfStringCarType 与不是真的。
我在 net.reflector 中检查了这个类型的类型,我发现它是一个字符串。
我知道没有意义。这是我寻求帮助的方式:/
【问题讨论】:
-
您能与我们分享异常消息吗?
-
对不起,也不例外。我的意思是错误。
-
您能否与我们分享相关信息无论是异常、错误还是其他原因? — 另外,“因为我必须有 KeyPairValuOfStringAndCarType”是什么意思?
-
感谢 intellisense 我知道,我的 webmethod 的参数是 KeyPairValuOfStringAndCarType。我可以在客户端创建这种类型的实例。错误是“参数类型“System.Collections.Generic.KeyValuePair
[]”不可分配给参数类型 mywebservicenamespace.KeyPairValuOfStringCarType -
KeyPairValuOfStringAndCarType 不等同于 KeyPairValuOfStringCarType
标签: c# web-services collections