Почему я получаю эту ошибку WCF, когда получаю?
Я написал метод контракта:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "TestEchoWithTemplate/{message}", BodyStyle = WebMessageBodyStyle.Bare)]
string TestEchoWithTemplate(string s);
и способ реализации:
public string TestEchoWithTemplate(string s)
{
return "You said " + s;
}
Когда я просматриваю URL:
http://localhost:52587/VLSContentService.svc/rest/TestEchoWithTemplate/HelloWorld
Я получаю следующую ошибку:
Операция TestEchoWithTemplate в контракте IVLSContentService имеет UriTemplate, который ожидает параметр с именем "MESSAGE", но в операции нет входного параметра с таким именем.
Следующее выдает ту же ошибку:
http://localhost:52587/VLSContentService.svc/rest/TestEchoWithTemplate/MESSAGE=HelloWorld http: // localhost: 52587 / VLSContentService.svc / rest / TestEchoWithTemplate? MESSAGE = HelloWorld
Что я делаю неправильно?
1 ответ
Решение
Определите шаблон как
"TestEchoWithTemplate/{s}"
Так как ваш метод имеет s
вместо message
, Или измените имя на message
в вашем интерфейсе:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "TestEchoWithTemplate/{message}", BodyStyle = WebMessageBodyStyle.Bare)]
string TestEchoWithTemplate(string message);