为什么在“GET”时出现此 WCF 错误?

发布于 2024-11-16 16:42:38 字数 1278 浏览 7 评论 0原文

我已经编写了方法契约:

[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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国际总奸 2024-11-23 16:42:38

将模板定义为

"TestEchoWithTemplate/{s}"

因为您的方法具有 s 而不是 message。或者在界面中将名称更改为 message

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文