开发者

WCF JSON object

    [OperationContract]
    [WebGet(RequestFormat = WebMessageFormat.Json)]
    public MyEmployee DoWorksINGLE()
    {

            return new MyEmployee("Bad", "Munner");


    }
 [DataContract]
    public class MyEmployee
    {
        public string FirstName = "";
        public string LastName = "";
        public MyEmployee(string F, string L)
        {
开发者_Python百科            FirstName = F;
            LastName = L;
        }
    }

I get following out put.

{"d":{"__type":"MyService.MyEmployee:#efleet"}}

Only the name of object not the values. can someone help?


I believe the JSON serializer only works against properties and not fields and they need to be marked with the DataMember attribute. Try converting the FirstName and LastName fields to properties and see if that fixes the problem.

[DataContract]
public class MyEmployee
{
    [DataMember]
    public string FirstName {get;set;}
    [DataMember]
    public string LastName {get;set;}
    ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜