1

在过去的几个小时里,我一直在用头撞墙,这就是我们正在尝试做的事情:一个方法需要一个原始/简单类型作为请求主体。最初我们尝试使用布尔值,但这不起作用,所以我们尝试使用字符串和对象。一样。

这是服务器端代码

[OperationContract]
[WebInvoke(UriTemplate = "/foo/{foo_id}/bar", Method = "POST", ResponseFormat=WebMessageFormat.JSON)]
string G(string foo_id, string content);

这是 Fiddler 中的请求:

标题:

User-Agent: Fiddler
Host: localhost
Content-Type: 'application/json',
Content-Length: 19

身体:

"hello_world"

我们尝试包装"hello_world"一个 json 对象,例如 {"content":"hello_world"} 但没有运气。

有什么想法吗?

4

1 回答 1

2

对我来说很好,这是我的代码:

[OperationContract]
[WebInvoke(UriTemplate = "/foo/{foo_id}/bar", Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
public string G(string foo_id, string content)
{
    return content + foo_id;
}

您没有设置请求格式(我知道很痛苦:))

这是我的提琴手请求:

User-Agent: Fiddler
Content-Type: application/json
Host: localhost:54287
Content-Length: 7
"Hello"
于 2009-05-13T21:04:36.227 回答