![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | 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? |
| | #2 (permalink) |
| Guest | 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? > |
| |
| |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| WPF: Own Control Derived From TextBox | hufaunder@yahoo.com | Avalon | 5 | 07-29-2007 08:49 PM |
| GUI application unable to display info derived from registry | Tony | Vista General | 3 | 02-05-2007 08:44 AM |