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」には、「MESSAGE」という名前のパラメーターを予期するUriTemplateがありますが、操作にその名前の入力パラメーターはありません。

次の場合も同じエラーが発生します。

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 に答える