In the WCF contract I’ve defined, there’s a class that has a property in it, and there’s a class that has a get in it because it’s read-only. As a result, the client reported an error.

    [DataContract]
    public class UserItem
    {
        public UserItem(int Id, string Name, bool IsActived)
        {
            this.Id = Id;
            this.Name = Name;
            this.IsActived = IsActived;
        }

        [DataMember]
        public int Id { get; set; }
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public bool IsActived { get; set; }
        [DataMember]
        public string BackGround
        {
            get
            {
                return IsActived
                    ? "UserItemNull.png"
                    : "UserItemNullg.png"; }}}Copy the code

At first, I thought it was a constructor, but tests found it wasn’t.

It turns out that the last property “BackGround” has no set!

In that case, fill in one:

    [DataContract]
    public class UserItem
    {
        public UserItem(int Id, string Name, bool IsActived)
        {
            this.Id = Id;
            this.Name = Name;
            this.IsActived = IsActived;
        }

        [DataMember]
        public int Id { get; set; }
        [DataMember]
        public string Name { get; set; }
        [DataMember]
        public bool IsActived { get; set; }
        [DataMember]
        public string BackGround
        {
            get
            {
                return IsActived
                    ? "UserItemNull.png"
                    : "UserItemNullg.png";
            }
            private set{; }}}Copy the code

Problem solved.