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"
加载中,请稍侯......
精彩评论