REST API发布请求 - 请求错误

时间:2014-09-26 00:16:15

标签: wcf rest wcf-data-services

enter image description here我有一个使用post方法的REST API调用。 WCF服务inturn将输入字符串保存到数据库。这是我的WCF合同

[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, UriTemplate = "/xxxx")]
int xxxx(string username);

当我在chrome上使用DHC客户端进行测试时,它会显示错误的请求错误。发送到服务器的json数据格式为{“username”:test123} 请找到下面的图像

发送到服务器的数据格式是否不正确?请建议。

1 个答案:

答案 0 :(得分:0)

合同应标有以下WebInvoke属性 - [WebInvoke(Method =" POST",BodyStyle = WebMessageBodyStyle.WrappedRequest,ResponseFormat = WebMessageFormat.Json,RequestFormat = WebMessageFormat.Json,UriTemplate =" / xxxx")