c# - 返回 List<string[]> 而不是 string[][]

标签 c# wcf

我有一个应该返回字符串数组列表的 WCF 服务:

[OperationContract]
List<string[]> ArticleSearch(int SearchField, string SearchValueMin,
           string SearchValueMax, IEnumerable<string> Fields);

我知道我可以从 System.Array 更改列表的反序列化至 System.Collections.Generic.List但这对我没用,因为我要么得到 string[][] (锯齿状数组)或 List<List<string>> (字符串列表的列表)作为返回类型。我需要 List<string[]> .

我的问题是;是否可以在某处配置它或者我是否必须更改 Reference.cs每次更新后手动归档?

最佳答案

通常集合类型作为数组返回,但您可以通过如下配置服务引用来更改此行为。

选择您的服务引用并转到配置服务引用...

在集合类型下拉列表中,选择类型 System.Collections.Generic.List

enter image description here

因为您的返回类型为 List<string[]>进行上述更改后,您将收到 List<List<string>>

所以你不能有列表的数组或数组的列表。

根据您的要求,您可以按照 Corak 的评论将数组转换为列表或将列表转换为数组。

关于c# - 返回 List<string[]> 而不是 string[][],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18628923/

相关文章:

c# - 寻找序列化方法或常量的解决方法

c# - 为什么几乎所有的类中Get都写在Set之前,有什么原因吗?

c# - 将 VS 项目文件的副本提供给其他开发人员

c# - 逐步在 ASP.Net Web API 上运行 swashbuckle

wcf - 创建无 session 或 session channel

使用 Ninject 在 Azure 上部署 WCF 服务时出现故障

c# - 具有路由属性的模糊 Controller 名称 : controllers with same name and different namespace for versioning

c# - 按 unicode 类别拆分字符串

c# - 清除 Web 浏览器控制所有站点的 cookie,而不清除 IE 本身

wcf - ServiceMetadataBehavior的HttpGetEnabled属性设置为true,HttpGetUrl属性是相对地址,但是没有http baseadd