![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | WCF DataContract and derived classes Hello. I've a qouestion about DataContracts and it's implementation. In my contract library i've define data contract class like this one: [DataContract] public class SyncData { private int _amount; [DataMember] public int Amount { get { return _amount; } set { _amount = value; } } } After that i created method at my ServiceContract class that accept argument of SyncData type. Like this: [ServiceContract] public class IMyService { void UpdateData(SyncData data); } This interface and SyncData class hosted at assembly that called Contract.dll. In ,y Client project i've made reference to the Contract.dll and define derived class of SyncData: public class SyncDataEx : SyncData { public void IncrementAmount() { this.Amount++; } } And made a remote call: SyncDataEx data = new SyncDataEx(); data.Amount = 1; data.IncrementAmount(); ClientProxy.UpdateData(data); //sic! I have an exception InvalidDataContractException:Type 'SyncDataEx' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Why object can't be serialized like SyncData type? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: WCF DataContract and derived classes In case you haven't already tried it. This should work, if you decorate SyncDataEx with the DataContract attribute. Alternatively you can get this to work by using the KnownType decoration. http://msdn2.microsoft.com/en-us/library/ms730167.aspx Cheers, -- Naraendirakumar R.R Senior Software Architect "Gomolyako Eduard" <eduard.gomolyako@gmail.com> wrote in message news:1182256843.993598.269790@q69g2000hsb.googlegroups.com... > Hello. I've a qouestion about DataContracts and it's implementation. > > In my contract library i've define data contract class like this one: > [DataContract] > public class SyncData > { > private int _amount; > > [DataMember] > public int Amount { get { return _amount; } set { _amount = > value; } } > } > > After that i created method at my ServiceContract class that accept > argument of SyncData type. Like this: > > [ServiceContract] > public class IMyService > { > void UpdateData(SyncData data); > } > > This interface and SyncData class hosted at assembly that called > Contract.dll. > > In ,y Client project i've made reference to the Contract.dll and > define derived class of SyncData: > > public class SyncDataEx : SyncData > { > public void IncrementAmount() > { > this.Amount++; > } > } > > And made a remote call: > SyncDataEx data = new SyncDataEx(); > > data.Amount = 1; > data.IncrementAmount(); > > ClientProxy.UpdateData(data); //sic! > > I have an exception InvalidDataContractException:Type 'SyncDataEx' > cannot be serialized. Consider marking it with the > DataContractAttribute attribute, and marking all of its members you > want serialized with the DataMemberAttribute attribute. > > Why object can't be serialized like SyncData type? > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| GUI application unable to display info derived from registry | Vista General | |||