Bien le bonsoir,

j'ai un petit soucis qui devrait être assez simple à régler j'imagine...

Voilà globalement l'idée : j'ai un service WCF qui expose différentes méthodes et quelques classes qu'il utilise... Et tout fonctionne sans soucis !

Sauf une chose : une de mes classes, "User", aurait besoin d'utiliser la méthode toString que j'ai overrider dans son code. Vu qu'il n'utilisait pas mon propre toString, je me suis dit que je devrais alors lui mettre l'attribut "[OperationContract]" mais aucun changement...

Voici toujours le code de la classe en question :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
 
namespace WCFService.Models
{
    [DataContract]
    public class User : ViewModelBase
    {
        [OperationContract]
        public override string ToString()
        {
            return Login;
        }
 
        private string _login;
        [DataMember]
        public string Login
        {
            get
            {
                return _login;
            }
            set
            {
                if (_login != value)
                {
                    _login = value;
                    NotifyPropertyChanged("Login");
                }
            }
        }
 
        private string _password;
        [DataMember]
        public string Password
        {
            get
            {
                return _password;
            }
            set
            {
                if (_password != value)
                {
                    _password = value;
                    NotifyPropertyChanged("Password");
                }
            }
        }
 
        private string _nom;
        [DataMember]
        public string Nom
        {
            get
            {
                return _nom;
            }
            set
            {
                if (_nom != value)
                {
                    _nom = value;
                    NotifyPropertyChanged("Nom");
                }
            }
        }
 
        private string _prenom;
        [DataMember]
        public string Prenom
        {
            get
            {
                return _prenom;
            }
            set
            {
                if (_prenom != value)
                {
                    _prenom = value;
                    NotifyPropertyChanged("Prenom");
                }
            }
        }
 
        private string _statut;
        [DataMember]
        public string Statut
        {
            get
            {
                return _statut;
            }
            set
            {
                if (_statut != value)
                {
                    _statut = value;
                    NotifyPropertyChanged("Statut");
                }
            }
        }
 
        private DateTime _dateNaissance;
        [DataMember]
        public DateTime DateNaissance
        {
            get
            {
                return _dateNaissance;
            }
            set
            {
                if (_dateNaissance != value)
                {
                    _dateNaissance = value;
                    NotifyPropertyChanged("DateNaissance");
                }
            }
        }
    }
}
Et tant qu'à faire, la classe dont elle hérite :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
namespace WCFService
{
    [DataContract]
    public abstract class ViewModelBase : INotifyPropertyChanged
    {
        #region Properties
 
        protected bool ThrowOnInvalidPropertyName { get; private set; }
 
        #endregion
 
        #region Constructor
 
        protected ViewModelBase()
        {
            ThrowOnInvalidPropertyName = true;
        }
 
        #endregion
 
        #region Events
 
        public event PropertyChangedEventHandler PropertyChanged;
 
        #endregion
 
        #region Event Handlers
 
        protected virtual void NotifyPropertyChanged(string propertyName)
        {
            VerifyPropertyName(propertyName);
 
            var handler = PropertyChanged;
            if (handler != null)
            {
                var e = new PropertyChangedEventArgs(propertyName);
                handler(this, e);
            }
        }
 
        #endregion
 
        #region Public Methods
 
        [Conditional("DEBUG")]
        [DebuggerStepThrough]
        public void VerifyPropertyName(string propertyName)
        {
            // Verify that the property name matches a real,  
            // public, instance property on this object.
            if (TypeDescriptor.GetProperties(this)[propertyName] == null)
            {
                var msg = "Invalid property name: " + propertyName;
 
                if (ThrowOnInvalidPropertyName)
                {
                    throw new Exception(msg);
                }
 
                Debug.Fail(msg);
            }
        }
 
        #endregion
    }
}
Une solution pour que mon toString soit pris en compte ? Merci d'avance !