如何在WCF restful服务中传递将作为json反序列化的参数?

时间:2017-02-20 21:59:48

标签: c# json rest wcf

合同

[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

1 个答案:

答案 0 :(得分:1)

您可以尝试以下

<强> Iservice.cs

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

service .cs

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