手动将 ClientBase 集合类型从 Array[] 更改为 List<> [英] Manually change the ClientBase collection type from Array[] to List&lt;&gt;

查看:24
本文介绍了手动将 ClientBase 集合类型从 Array[] 更改为 List<>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将自己的 WCF 代理与 ClientBase 一起使用,我想做一些类似于 svc util 中的 ct 属性的操作,并告诉代理返回 List<> 集合类型.

I'm using my own WCF proxy with ClientBase, I want to do somthing like the ct attribute in the svc util, and tell the proxy to return the List<> collection type.

我不能使用 List<> 因为实体由 nhibernate 管理所以我必须使用 IList

i cant use List<> because the entities managed by nhibernate so i have to use IList

代理不是用 svcutil 生成的....我自己写的.

the proxy was not generated with svcutil.... i wrote it my self.

我该怎么做?

推荐答案

遗憾的是,当合约中声明的类型是 IList 之类的接口类型时,无法控制 WCF 实际实例化的类型(实际上,它将是一个数组).

Unfortunately, when the declared type in the contract is an interface type like IList, there is no way to control what type WCF will actually instantiate (in practice, it will be an array).

请参阅 http://msdn.microsoft.com/en-us/图书馆/aa347850.aspx:

"在反序列化过程中,当声明的类型为接口时,序列化引擎选择实现声明接口的类型,并实例化该类型.已知类型机制(在数据契约已知类型中描述)没有效果在这里;类型选择内置于 WCF."

这篇关于手动将 ClientBase 集合类型从 Array[] 更改为 List<>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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