开发者

How set Two values in one Name with UriTemplate?

开发者 https://www.devze.com 2022-12-13 12:40 出处:网络
I created this code: [OperationContract] [WebGet(UriTemplate = \"detect?v=1.0&q={q}\", BodyStyle = WebMessageBodyStyle.Bare)]

I created this code:

[OperationContract]
[WebGet(UriTemplate = "detect?v=1.0&q={q}", BodyStyle = WebMessageBodyStyle.Bare)]
DetectLanguage GetDetectLanguage(string q);开发者_JS百科

[OperationContract]
[WebGet(UriTemplate = "translate?v=1.0&q={query}&(langpair={from}|{to})", BodyStyle = WebMessageBodyStyle.Bare)]
TranslateLanguage GetTranslateLanguage(string query, string from, string to);

But I get this error:

The UriTemplate 'translate?v=1.0&q={query}&(langpair={from}|{to})' is not valid; each portion of the query string must be of the form 'name=value', when value cannot be a compound segment. See the documentation for UriTemplate for more details.

I know (name=value). How do I get Name={value1}|{value2}? Is it possible?

Or any other solution!


As the error message explains, you cannot have langpair={from}|{to} because that would apparently be a compounded value.

You can use the form

langpair={langpair}

and then use String.Split in your method to get the two parts:

string langpair = "en|fr";
string[] parts = langpair.Split('|');
string from = parts[0];  // "en"
string to = parts[1];    // "fr"
0

精彩评论

暂无评论...
验证码 换一张
取 消