0

我正在使用主干.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;}    
}

发布 Json

{“姓名”:“欢迎客人”}

Http 详细信息

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
4

1 回答 1

1

您的原始请求应如下所示:

POST http://localhost:54897/Sample.svc/Todos HTTP 1.1
Content-Type: application/json
Host: localhost

{"instance":{"Name":"This is my first todo"}
于 2012-07-05T11:12:20.937 回答