views:

37

answers:

1
+1  Q: 

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)
        {
            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?

+1  A: 

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;}
    ...
}
JaredPar
Thanks it works.
malik
if i want to return a list of object of Entity Framework type.
malik