0

I am trying to send the model to a wcf service. First i had a serialization problem but i solved it by setting

ContextOptions.ProxyCreationEnabled = false;

referrer DataContractSerializer Error using Entity Framework 4.0 with WCF 4.0 but now models Properties Tax and Products are null

public ClientWindowViewModel()
    {
        Ip = ServerWindowViewModel.LocalIP;
        db = new STOREDBEntities();
        db.Configuration.ProxyCreationEnabled = false;
        products = db.Products;//.Where(p => p.IsSynced == false)
    }

Product Model

public partial class Product
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public Product()
        {
            this.Categories = new HashSet<Category>();
        }

        public int Id { get; set; }
        public string ProductName { get; set; }
        public byte[] Image { get; set; }
        public bool IsDeleted { get; set; }
        public bool IsSynced { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<Category> Categories { get; set; }
        public virtual Tax Tax { get; set; }
    }

Send To WCF Server

channel.Update(checkedProducts);
Felix Castor
  • 1,598
  • 1
  • 18
  • 39
Erik Hakobyan
  • 1,024
  • 9
  • 16

1 Answers1

0

Correct me if i am wrong, you want to send Product class by a WCF contract and after you send it you get only nulls and default values?

You can not send objects by a WCF without setting a proper annotations like [DataContract], [DataMember] in the Product class.

Set [DataContract] above the class, and [DataMember] above each property. Without this the message will not be properly serialized.

Paweł Górszczak
  • 524
  • 1
  • 5
  • 12