为什么在“获取"时出现此WCF错误? [英] Why do I get this WCF error when 'GET'ing?

查看:117
本文介绍了为什么在“获取"时出现此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;
    }

当我浏览到网址时:

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

我收到以下错误:

操作"TestEchoWithTemplate" 合同"IVLSContentService"具有 需要参数的UriTemplate 名为"MESSAGE",但没有输入 在该名称上具有该参数的参数 操作.

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

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

我在做什么错了?

推荐答案

将模板定义为

"TestEchoWithTemplate/{s}"

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

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

这篇关于为什么在“获取"时出现此WCF错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆