我正在使用backbone.js并将模型(todo)发布到wcf Rest服务,其详细信息可在下面找到。由于某种原因,无论发布的json如何,实现总是会收到一个空值。
[WebInvoke(ResponseFormat = WebMessageFormat.Json, Method = "POST", UriTemplate = "Todos", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
[OperationContract]
Wallet CreateTodos(Todo instance);
public Wallet CreateTodos(Todo instance)
{
if (instance == null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotAcceptable;
return null;
}
... blah blah blah
[DataContract]
Public Class Todo
{
[DataMember]
public string Name{get;set;}
}
{ “名字”:“欢迎客人” }
Accept:application/json, text/javascript, */*; q=0.01
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Content-Length:281
Content-Type:application/json
Host:localhost
Origin:http://localhost
Pragma:no-cache
Referer:http://localhost/todos/index.html
X-Requested-With:XMLHttpRequest
答案 0 :(得分:1)
您的原始请求应如下所示:
POST http://localhost:54897/Sample.svc/Todos HTTP 1.1
Content-Type: application/json
Host: localhost
{"instance":{"Name":"This is my first todo"}