Exi*_*tos 4 c# rest wcf uritemplate
我写了方法合同:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "TestEchoWithTemplate/{message}", BodyStyle = WebMessageBodyStyle.Bare)]
string TestEchoWithTemplate(string s);
Run Code Online (Sandbox Code Playgroud)
和实施方法:
public string TestEchoWithTemplate(string s)
{
return "You said " + s;
}
Run Code Online (Sandbox Code Playgroud)
当我浏览到Url时:
HTTP://本地主机:52587/VLSContentService.svc/REST/TestEchoWithTemplate /的HelloWorld
我收到以下错误:
合同'IVLSContentService'中的'TestEchoWithTemplate'操作有一个UriTemplate,它需要一个名为'MESSAGE'的参数,但操作上没有带该名称的输入参数.
以下产生相同的错误:
HTTP://本地主机:52587/VLSContentService.svc/REST/TestEchoWithTemplate/MESSAGE =的HelloWorld 的http://本地主机:52587/VLSContentService.svc/REST/TestEchoWithTemplate消息=的HelloWorld
我究竟做错了什么?
将模板定义为
"TestEchoWithTemplate/{s}"
Run Code Online (Sandbox Code Playgroud)
因为你的方法s代替了message.或者message在界面中更改名称:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "TestEchoWithTemplate/{message}", BodyStyle = WebMessageBodyStyle.Bare)]
string TestEchoWithTemplate(string message);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5145 次 |
| 最近记录: |