namespace WcfRestService2.Model
{
[DataContract]
public class InternalInfoEW : ServiceInfoEW
{
[DataMember]
public bool? Good { get; set; }
[DataMember]
public int Loop { get; set; }
[DataMember]
public Dealer DealerInf { get; set; }
[DataMember]
public IList<CommentsHistory> Commenter { get; set; }
[DataMember]
public IList<CommentsHistory> Comments { get; set; }
[DataMember]
public IList<CommentsHistory> CommentsInternal { get; set; }
[DataMember]
public IList<ReplyInfoHistory> SRReplyHistory { get; set; }
}
}
新建(Http/POST),POST里的数据格式通过RequestFormat定义为Json,WCF框架接受到Json数据的请求,会自动反序列化成InternalInfoEW实例。但是反序列化失败,报错object reference not set to an object,不知道为什么?求高手指点
代码如下:
[WebInvoke(UriTemplate = "Tasks/Add", Method = "POST",
RequestFormat=WebMessageFormat.Json)]
public void Create(InternalInfoEW pocoTask)
{
var ctx = WebOperationContext.Current;
try
{
using (var db = new TasksEntities())
{
}
}
catch (Exception ex)
{
ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.ExpectationFailed;
ctx.OutgoingResponse.StatusDescription = ex.Message;
}
}
你看下你的json数据是什么,为空呢?还是反序列化就失败了,无法反序列化InternalInfoEW对象