为什么在“GET”时出现此 WCF 错误?
我已经编写了方法契约:
[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< /a>
我收到以下错误:
操作“TestEchoWithTemplate” 合同“IVLSContentService”有一个 需要参数的 UriTemplate 名为“MESSAGE”,但没有输入 带有该名称的参数 操作。
以下产生相同的错误:
http://localhost:52587/VLSContentService.svc/休息/TestEchoWithTemplate/MESSAGE=HelloWorld http://localhost:52587/VLSContentService.svc/rest/TestEchoWithTemplate?MESSAGE=HelloWorld
我做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将模板定义为
因为您的方法具有
s
而不是message
。或者在界面中将名称更改为message
:Define the template as
Since your method has
s
instead ofmessage
. Alternatively change the name tomessage
in your interface: