尝试发布到wcf rest 4服务时请求错误
我正在使用WCF4.0REST模板,并试图让它与jquery一起工作 我创建了一个新的rest模板项目,并在同一个项目中添加了一个webform,以简化工作 我稍微修改了Create方法,使其看起来像这样尝试发布到wcf rest 4服务时请求错误,rest,jquery,wcf-rest,Rest,Jquery,Wcf Rest,我正在使用WCF4.0REST模板,并试图让它与jquery一起工作 我创建了一个新的rest模板项目,并在同一个项目中添加了一个webform,以简化工作 我稍微修改了Create方法,使其看起来像这样 [WebInvoke(UriTemplate = "", Method = "POST")] public string Create(SampleItem instance) { // TODO: Add the new instance of Sampl
[WebInvoke(UriTemplate = "", Method = "POST")]
public string Create(SampleItem instance)
{
// TODO: Add the new instance of SampleItem to the collection
return (instance.Id == 1) ? "1 was returned" : "something else was returned";
}
然后从我的网络表单中,我使用这个
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: 'POST',
url: "/service1/",
data: { "Id": 1,"StringValue": "String content"
},
success: function (data) {
$('.result').html(data);
},
error: function (error) {
$('.result').html(error)
},
dataType: "json",
contentType: "application/json; charset=utf-8"
});
});
</script>
<div class="result"></div>
$(文档).ready(函数(){
$.ajax({
键入:“POST”,
url:“/service1/”,
数据:{“Id”:1,“StringValue”:“字符串内容”
},
成功:功能(数据){
$('.result').html(数据);
},
错误:函数(错误){
$('.result').html(错误)
},
数据类型:“json”,
contentType:“应用程序/json;字符集=utf-8”
});
});
然而,fiddler返回了一个400错误,告诉我有一个请求错误。我做错什么了吗?400也可能意味着你的服务出了问题。您是否尝试将调试器附加到Rest服务? 是否尝试创建.Net控制台应用程序(使用HttpClient创建请求)并与您的服务通信 我遇到了同样的错误,在半小时的测试后,我看到REST服务中发生了一些错误