10

I am using Fody in a SilverLight project to auto-generate property dependencies. However, it doesn't work if setters already contain a RaisePropertyChanged method call.

A workaround could be to generate web service reference code without INotifyPropertyChanged and instead implement it in a partial method.

How can I generate web service reference code without INotifyPropertyChanged?

I have a WCF service, let's call it MaterialService.svc. It looks something like this:

[ServiceContract]
public interface IMaterialService
{
    [OperationContract]
    Material GetMaterial(int id);
}

[DataContract]
public class Material
{
    [DataMember]
    public int ID { get; set; }

    [DataMember]
    public string Name { get; set; }
}

When I add the service as a Service Reference and generate client code, every class is set to implement INotifyPropertyChanged:

public partial class Material : object, System.ComponentModel.INotifyPropertyChanged {

    private int IDField;

    private string NameField;

    [System.Runtime.Serialization.DataMemberAttribute()]
    public int ID {
        get {
            return this.IDField;
        }
        set {
            if ((this.IDField.Equals(value) != true)) {
                this.IDField = value;
                this.RaisePropertyChanged("ID");
            }
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute()]
    public System.Nullable<string> Name {
        get {
            return this.NameField;
        }
        set {
            if ((this.NameField.Equals(value) != true)) {
                this.NameField = value;
                this.RaisePropertyChanged("Name");
            }
        }
    }
}

How can I generate client code that doesn't implement INotifyPropertyChanged?

iCollect.it Ltd
  • 92,391
  • 25
  • 181
  • 202
Geir Sagberg
  • 9,632
  • 8
  • 45
  • 60

1 Answers1

17

After you add the service reference, open the file Reference.svcmap under the service reference (you may need to enable the "show all files" option in the "Project" menu). There find the <EnableDataBinding> element, and change the value to false. That will remove the INotifyPropertyChanged from the generated data contracts.

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
  • It works, thanks a lot :) For anyone having the same issue as me re Fody, I contacted Simon Cropp and he made a new version that supports existing RaisePropertyChanged calls, so that also fixed the problem, but still this is nice to know :) – Geir Sagberg Aug 14 '12 at 07:43