如何在没有INotifyPropertyChanged的情况下生成Web服务引用?

时间:2012-08-10 13:49:11

标签: c# .net wcf silverlight inotifypropertychanged

我在SilverLight项目中使用Fody来自动生成属性依赖项。但是,如果setter已经包含RaisePropertyChanged方法调用,则它不起作用。

解决方法可能是生成不使用INotifyPropertyChanged的Web服务引用代码,而是使用部分方法实现它。

如何在没有INotifyPropertyChanged的情况下生成网络服务参考代码?

我有一个WCF服务,我们称之为MaterialService.svc。它看起来像这样:

[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; }
}

当我将服务添加为服务引用并生成客户端代码时,每个类都设置为实现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");
            }
        }
    }
}

如何生成未实现INotifyPropertyChanged的客户端代码?

1 个答案:

答案 0 :(得分:14)

添加服务引用后,在服务引用下打开文件Reference.svcmap(您可能需要在“项目”菜单中启用“显示所有文件”选项)。找到<EnableDataBinding>元素,并将值更改为false。这将从生成的数据合同中删除INotifyPropertyChanged

相关问题