我应该为WCF服务使用什么JSON
我正在使用这些方法运行WCF服务我应该为WCF服务使用什么JSON,wcf,json,Wcf,Json,我正在使用这些方法运行WCF服务 public string UploadInspections(Inspection[] inspections) public string UploadInspection(Inspection inspection) [DataContract] public partial class Inspection { [DataMember] public DateTime DateTime { get; set; } [DataM
public string UploadInspections(Inspection[] inspections)
public string UploadInspection(Inspection inspection)
[DataContract]
public partial class Inspection
{
[DataMember]
public DateTime DateTime { get; set; }
[DataMember]
public int Id { get; set; }
[DataMember]
public string Comment { get; set; }
[DataMember]
public int Rating { get; set; }
}
在javascript中,我尝试使用JSON调用这些方法的帖子。UploadInspection方法的JSON是这样的
{"Id":10,"Comment":"New One","Rating":3}
调用了UploadInspection方法,但检查对象设置为null
我不确定如何使用JSON指定日期字段,我认为解析器可能不喜欢没有日期字段的JSON。我从检查对象中删除了日期字段,但发生了同样的事情
对于UploadInspections方法(即数组),JSON应该是什么样的?我尝试了一些JSON
"inspections": [{"Id":10,"Comment":"New One","Rating":3}]
还有这个,
[{"Id":10,"Comment":"New One","Rating":3}, {"Id":11,"Comment":"New Two","Rating":2}]
但是我犯了这个错误
OperationFormatter encountered an invalid Message body. Expected to find an attribute with name 'type' and value 'object'. Found value 'string'.
问题不是我想的那样,在我的服务定义中,最初看起来是这样的
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
[OperationContract]
string UploadInspections(Inspection[] inspections);
一旦我取下这个
BodyStyle = WebMessageBodyStyle.WrappedRequest
成功了 工作得很有魅力。谢谢Atul SurekaYup就是这样。万分感谢!那是我生命中的4个小时,我的头发有好几束,我再也找不回来了。谢谢