Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get this WCF error when 'GET'ing?

I have written the method contract:

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

and the implementing method:

  public string TestEchoWithTemplate(string s)
    {
        return "You said " + s;
    }

When I browse to the Url:

http://localhost:52587/VLSContentService.svc/rest/TestEchoWithTemplate/HelloWorld

I get the following error:

Operation 'TestEchoWithTemplate' in contract 'IVLSContentService' has a UriTemplate that expects a parameter named 'MESSAGE', but there is no input parameter with that name on the operation.

The following produce the same error:

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

What am I doing wrong?

like image 848
Exitos Avatar asked Jun 21 '11 11:06

Exitos


1 Answers

Define the template as

"TestEchoWithTemplate/{s}"

Since your method has s instead of message. Alternatively change the name to message in your interface:

[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "TestEchoWithTemplate/{message}", BodyStyle = WebMessageBodyStyle.Bare)]
string TestEchoWithTemplate(string message);
like image 83
Aliostad Avatar answered Sep 21 '22 13:09

Aliostad