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

喜你入骨 提交于 2020-01-24 07:46:04

问题


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?


回答1:


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);


来源:https://stackoverflow.com/questions/6424670/why-do-i-get-this-wcf-error-when-geting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!