首页 新闻 会员 周边

WCF--关于传递数据格式问题

0
悬赏园豆:10 [待解决问题]

应用场景:

客户端:输入 城市/日期 列表 来查询天气

服务端:返回 城市/日期/天气 列表

我是用.Net(C#)开发的,需要给PHP,Java等调用

问题:我用List<>来做传递参数和返回值有问题。就是用List来做参数或者返回值不对。我是用[DataContract][DataMember]来约束的

如何解决呢?谢谢了

Zach Feng的主页 Zach Feng | 初学一级 | 园豆:190
提问于:2011-07-07 11:44
< >
分享
所有回答(1)
0

是的,我也遇到过这种问题,List<实体类型>时,就会有问题,改成List<Int>等类型时就可以了,你试试改成List<String>,或者是用Json传递。希望对你有点帮助

加百力 | 园豆:533 (小虾三级) | 2011-07-07 11:51
我测试过,使用List时,在客户端就变成string[]。是不是要把List<实体类型>改用XML或者Json数据格式才行?
谢谢Fisherman 热情回答。
支持(0) 反对(0) Zach Feng | 园豆:190 (初学一级) | 2011-07-07 12:11
我找到办法了,但是对于要给Java/PHP调用用List作为返回值/参数还是有问题:
You can specify that you want to use a generic list instead of an array by clicking the advanced button when you add a reference, or you can right click on the service reference and choose configure to change it in place.

The reason is that WCF serializes Generic lists as arrays to send across the wire. The configuration is just telling svcutil to create a proxy that converts them back to a generic list for your convenience.
支持(0) 反对(0) Zach Feng | 园豆:190 (初学一级) | 2011-07-07 14:03
[CollectionDataContract]
[KnownType(typeof(Parent))]
public class CustomCollection : List
{
}
使用上面方式最终解决问题了
支持(0) 反对(0) Zach Feng | 园豆:190 (初学一级) | 2011-07-07 15:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册