开发者

WCF JSON object

开发者 https://www.devze.com 2022-12-13 03:35 出处:网络
[OperationContract] [WebGet(RequestFormat = WebMessageFormat.Json)] public MyEmployee DoWorksINGLE() { return new MyEmployee(\"Bad\", \"Munner\");
    [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

精彩评论

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

关注公众号