【问题标题】:List<string> and string[] WCF? [duplicate]List<string> 和 string[] WCF? [复制]
【发布时间】:2017-11-29 06:29:34
【问题描述】:

我创建了一个 WCF 服务并公开了一个接受 List 作为参数的函数。

public bool Execute(string databaseServer, string database, string ClientName, string ERAPayerID, string PlanPriority, List<string> AdjCode, List<string> RemarkCode, List<string> CPT, string Modifier, string renderingProviderNPI)

当我调用这个函数时,它要求我提供 string[] 而不是 列表

WriteOffServiceClient client = new WriteOffServiceClient();
bool resutl = client.Execute("server", "database", practiseIdentifier, "", ERAPayerId, pPriority, new List<string>, new List<string>, new List<string>, "", "");

它给了我这个无效参数的错误。当我用字符串调用它时,它接受它。

WriteOffServiceClient client = new WriteOffServiceClient();
bool resutl = client.Execute("server", "database", practiseIdentifier, "", ERAPayerId, pPriority, new string[5], new string[5], new string[5], "", "");

如果我只想接受列表,我该怎么办?

【问题讨论】:

  • 你为什么要接受一个列表呢?超过 90% 的情况您只需要在参数上执行 foreach,因此您只需要 IEnumerable&lt;T&gt;
  • 因为我在服务端有一些基于 .isGenericType==true 或 false 决定的逻辑。
  • List&lt;T&gt; 并不比 IEnumerable&lt;T&gt; 更通用...

标签: c# .net wcf


【解决方案1】:

这与您添加服务参考的方式有关。您可以在添加服务引用时选择集合类型。

添加服务参考 -> 输入您的网址并使用高级按钮您可以选择System.Collection.Generic.List 进行收集选项。

【讨论】:

  • 完美!像魅力一样工作谢谢
猜你喜欢
  • 2014-07-22
  • 2017-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-26
相关资源
最近更新 更多