dotnet / wcf

This repo contains the client-oriented WCF libraries that enable applications built on .NET Core to communicate with WCF services.
MIT License
1.72k stars 558 forks source link

Implement INotifyPropertyChanged on data types #2205

Closed sherland closed 5 years ago

sherland commented 7 years ago

The types generated are not implementing INotifyPropertyChanged. Example on .net:

public partial class MyEntity : ... System.ComponentModel.INotifyPropertyChanged {
        ...
        [System.Runtime.Serialization.DataMemberAttribute()]
        public bool MyProperty {
            get {
                return this.MyPropertyField;
            }
            set {
                if ((this.MyPropertyField.Equals(value) != true)) {
                    this.MyPropertyField = value;
                    this.RaisePropertyChanged("MyPropertyField");
                }
            }
        }
        ...
        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName) {
            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if ((propertyChanged != null)) {
                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }

Currently this is generated in a netstandard2.0 project:

public partial class MyEntity
{
        ...
        [System.Runtime.Serialization.DataMemberAttribute()]
        public bool MyProperty
        {
            get
            {
                return this.MyPropertyField;
            }
            set
            {
                this.MyPropertyField= value;
            }
        }
hongdai commented 7 years ago

@sherland Dotnet core does not support data binding as you notice.

Could you outline your scenario that needs the support? We can evaluate the support if there are sufficient demand.

Thanks, Hong Dai

sherland commented 7 years ago

It's only the generated code that have issues: When i update the proxy manually (make it more similar to what .net generates) and compile a netstandard2 library, and use it in netcore2, everything works as expected. Netcore2 have the required classes it seems.

My scenario: We have created a api (very) similar to entity-framework, with linq support, change-tracking and all on top of a custom wcf api. When the entities doesnt implement INotifyPropertyChanged, we are unable to do change-tracking in a good way.

The wcf service exposes a couple of hundred entities with a large amount of properties. Manually updating this when we add new fields to the entities would take a lot of time.

hongdai commented 7 years ago

@sherland Thanks for your detailed scenario description! It will help us evaluate the support.

mlacouture commented 6 years ago

Hi @sherland, maybe you already have a solution for your issue but in case you may still benefit from this feature, you can use the dotnet-svcutil tool which implements this feature, just run the tool with the --enableDataBinding option:

dotnet svcutil <url> --enableDataBinding

hope this helps,

Pol63 commented 6 years ago

wpf will be enabled with .net core 3 so if the wizard could propose to implement inotifypropertychanged ...

dasetser commented 5 years ago

Closing since this is supported by dotnet-svcutil. This doesn't seem like a very common scenario so I don't think we need to add this to the WCF Web Service Reference Provider UI.

If there's a reason you need to use the UI instead of dotnet-svcutil you can get it to generate with this by adding the service reference normally, modifying the the ConnectedService.json file to add the option, then updating the service reference. The line you need to add to the json file is:

"enableDataBinding": true,

jnm2 commented 4 years ago

Please add an 'Implement INotifyPropertyChanged' checkbox in the UI. INotifyPropertyChanged isn't only for data binding.

A UI option will help people who are porting applications to .NET Core.

klenium commented 4 years ago

@dasetser

If there's a reason you need to use the UI instead of dotnet-svcutil

Yes, there is. People will not waste hours for searching for this solution if the GUI that is opened first by everyone can offer it. It was really hard to find for this topic, almost no question, documentation, examples about WCF+proprty change. Google was not my friend.

I will not know that a lot of years ago when other people created our project in .NET Framework, they could generate objects with INotifyPropertyChanged added, and they didn't have to add these part by hand. If the option is not available in the GUI that I use to generate the code, I'll have to search if this is still possible and what workarounds are there. If a checkbox is there, I save a lot of time. Of course I don't know there is a separated tool for this, why would I? Pretty simple: if it is possible, make it configurable, or at least put a link for describing "more options".

Please, when you remove a part from the old .NET Framework that worked perfectly in many projects, don't stop at saying "this is possible in somewhere else". Well if I write assembly directly, everything can be possible. At least create an article for this topic that we can find via Google.

klenium commented 4 years ago

And a very common scenario: we fill xxxSpecified fields by using change tracking on the main properties. This pattern is used by a lot of services. For safety, it is important to do this automatically and not from code, since anyone could forget to set xxxSpecified to true.

stogle commented 4 years ago

@dasetser @jnm2 @klenium I created a feature request for the UI change here: https://developercommunity.visualstudio.com/idea/1165673/please-add-a-checkbox-for-enabledatabindings-to-mi.html

Montago commented 2 years ago

Closing since this is supported by dotnet-svcutil. This doesn't seem like a very common scenario so I don't think we need to add this to the WCF Web Service Reference Provider UI.

If there's a reason you need to use the UI instead of dotnet-svcutil you can get it to generate with this by adding the service reference normally, modifying the the ConnectedService.json file to add the option, then updating the service reference. The line you need to add to the json file is:

"enableDataBinding": true,

This isn't working for me..

I've tried adding it to the JSON file and then refreshing via the GUI -- didnt work I've tried adding it and then updating the SVC via the dotnet-svcutil -- didnt work

Montago commented 1 year ago

why is this issue closed when its still not working ?