【问题标题】:WCF : send multiple params with same nameWCF:发送多个具有相同名称的参数
【发布时间】:2014-05-13 22:29:49
【问题描述】:

我想通过 GET 将相同类型的项目列表发送到我的 WCF 服务。 例如:

MySite.com?MyService.svc\MyMethod?Id=1&Id=2&Id=3 .....

还有我的方法

[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public void MyMethod( ???????? )
{
 //here i want to get the list of all the id's i've sent
}

或者可能有另一种发送此类数据的方式(我的意思是,具有随机长度的 ID 的“数组”

统一更新: 我已经尝试过 List 和字符串 [] (无论如何,它是字符串,但是)但是异常说:'type 'System.String[]' is not convertible by 'QueryStringConverter'。'

【问题讨论】:

  • 我已经尝试了 List 和 string [] (无论如何,它是字符串,但是)但是异常说:'type 'System.String[]' is not convertible by ' QueryStringConverter'.'

标签: c# asp.net wcf get


【解决方案1】:

您可以尝试使用params 关键字。比如:

public void MyMethod(params object[] list)
{
    // access by index like list[0] etc.
}

如果需要,您可以使用intstring 代替object 类型。

您可以在http://msdn.microsoft.com/en-us/library/w5zay9db.aspx 阅读有关params 的更多信息。

【讨论】:

  • 谢谢,但我仍然有一个错误,例如 ... 有一个名为 'list' 的查询变量,类型为 'System.Object[]',但类型 'System.Object[]' 是不可转换的通过'QueryStringConverter'。
  • @V319 mb 这个话题会帮助你stackoverflow.com/questions/6445171/…
猜你喜欢
  • 2020-10-20
  • 2016-02-04
  • 1970-01-01
  • 1970-01-01
  • 2015-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多