Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Indigo

Vista - WCF DataContract and derived classes

 
 
Old 06-19-2007   #1 (permalink)
Gomolyako Eduard


 
 

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 SpecsSystem Spec
Old 07-03-2007   #2 (permalink)
Naraendirakumar R.R.


 
 

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 SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
GUI application unable to display info derived from registry Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

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