5

我已经写了方法契约:

[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

我收到以下错误:

合同“IVLSContentService”中的操作“TestEchoWithTemplate”有一个 UriTemplate,它需要一个名为“MESSAGE”的参数,但操作中没有具有该名称的输入参数。

以下产生相同的错误:

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

我究竟做错了什么?

4

1 回答 1

8

将模板定义为

"TestEchoWithTemplate/{s}"

由于您的方法有s而不是message. message或者在您的界面中将名称更改为:

[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "TestEchoWithTemplate/{message}", BodyStyle = WebMessageBodyStyle.Bare)]
string TestEchoWithTemplate(string message);
于 2011-06-21T11:43:31.303 回答