Почему я получаю эту ошибку WCF, когда получаю? - PullRequest
4 голосов
/ 21 июня 2011

Я написал контракт на метод:

[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, который ожидает параметр с именем «СООБЩЕНИЕ», но нет ввода параметр с этим именем на работа.

Следующее выдает ту же ошибку:

http://localhost:52587/VLSContentService.svc/rest/TestEchoWithTemplate/MESSAGE=HelloWorld http://localhost:52587/VLSContentService.svc/rest/TestEchoWithTemplate?MESSAGE=HelloWorld

Что я делаю не так?

1 Ответ

7 голосов
/ 21 июня 2011

Определить шаблон как

"TestEchoWithTemplate/{s}"

Так как ваш метод имеет s вместо message. В качестве альтернативы измените имя на message в вашем интерфейсе:

[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "TestEchoWithTemplate/{message}", BodyStyle = WebMessageBodyStyle.Bare)]
string TestEchoWithTemplate(string message);
...