Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Indigo

WCF DataContract and derived classes

 
 
Thread Tools Display Modes
Old 06-19-2007   #1 (permalink)
Gomolyako Eduard
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?

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








Vistax64.com 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 2005-2008

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