【问题标题】:How to pass parameter that will be deserialize as json in WCF restful service?如何在 WCF RESTful 服务中传递将反序列化为 json 的参数?
【发布时间】:2017-07-10 08:20:16
【问题描述】:

合同

[OperationContract]
[WebGet(UriTemplate = "Filter/{paramName:paramValue}/"),  
 RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
string[] Filter(string paramNameAndparamValue);

实现

public string Filter(string paramNameAndparamValue)
{
     string[] tmp = paramNameAndparamValue.split(':');

     // do something ... 
}

有什么理由要向这个restful方法传递一个将用作json对象的参数并避免使用string.split

【问题讨论】:

  • 将参数标记为数组,如Filter(string[] paramNameAndparamValue)?请注意,您的合同和您的实现在返回类型上有所不同。
  • 在这种情况下 - 我将如何将参数传递给 restful ?如何传递 2 字符串?
  • 如果我将使用字符串[],如何编写 [WebGet(UriTemplate = "Filter/{paramName:paramValue}/") 行
  • 或者,实际上,只需将您的 URI 模板更改为 "Filter/{paramName}:{paramValue}/" 并将签名更改为 string[] Filter(string paramName, string paramValue)

标签: c# json rest wcf


【解决方案1】:

你可以像下面这样尝试

Iservice.cs

 [OperationContract]
[WebGet(UriTemplate = "Filter/{paramName}/{paramValue}"),  
 RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
string[] Filter(string paramName,string paramValue);

服务.cs

public string[] Filter(string paramName,string paramValue);
{
    //your code;
}

【讨论】:

    猜你喜欢
    • 2015-06-03
    • 2011-10-10
    • 1970-01-01
    • 2015-02-13
    • 2014-03-04
    • 1970-01-01
    • 2012-12-04
    • 1970-01-01
    • 2016-04-16
    相关资源
    最近更新 更多