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

Serialization and inheritance

Update your Vista Drivers Update Your Drivers Now!!
 
 
Thread Tools Display Modes
Old 03-04-2006   #1 (permalink)
ianic
Guest


 

Serialization and inheritance

On both client and server side I have this DataContract and the
communication works fine:

[DataContract(Name = "Person", Namespace = "ServiceLibrary")]
public class Person
{
[DataMember]
public int Id;
[DataMember]
public string FirstName;
[DataMember]
public string LastName;
}

Now I want to change ONLY client to something like this:

[DataContract(Namespace = "ServiceLibrary")]
public class PersonBase
{
[DataMember]
public string LastName;
}

[DataContract(Name = "Person", Namespace = "ServiceLibrary")]
public class Person : PersonBase
{
[DataMember]
public int Id;
[DataMember]
public string FirstName;
}


I tried with various attributes combination to get the thing working but
without success.
Is there any documentation on the subject?
Does anyone has the idea weather something like this is possible?

Thanks,
Igor.

My System SpecsSystem Spec
Old 03-04-2006   #2 (permalink)
Juval Lowy
Guest


 

Re: Serialization and inheritance

Hello Igor,

I think the problem you are running into is that the order of the members
has to match. It serializes the base class first, so LastName is first, unlike
Id in the original contract (plain alphabetically). Use the Order property
to force the correct order.

Thanks,

Juval Lowy.




> On both client and server side I have this DataContract and the
> communication works fine:
>
> [DataContract(Name = "Person", Namespace = "ServiceLibrary")]
> public class Person
> {
> [DataMember]
> public int Id;
> [DataMember]
> public string FirstName;
> [DataMember]
> public string LastName;
> }
> Now I want to change ONLY client to something like this:
>
> [DataContract(Namespace = "ServiceLibrary")]
> public class PersonBase
> {
> [DataMember]
> public string LastName;
> }
> [DataContract(Name = "Person", Namespace = "ServiceLibrary")]
> public class Person : PersonBase
> {
> [DataMember]
> public int Id;
> [DataMember]
> public string FirstName;
> }
> I tried with various attributes combination to get the thing working
> but
> without success.
> Is there any documentation on the subject?
> Does anyone has the idea weather something like this is possible?
> Thanks,
> Igor.



My System SpecsSystem Spec
Old 03-04-2006   #3 (permalink)
ianic
Guest


 

Re: Serialization and inheritance

Thanks Juval I got that working, although imho, it is pretty strange
that the order of the elements in the message means so much to the
formatter.


Juval Lowy wrote:
> Hello Igor,
>
> I think the problem you are running into is that the order of the
> members has to match. It serializes the base class first, so LastName is
> first, unlike Id in the original contract (plain alphabetically). Use
> the Order property to force the correct order.
> Thanks,
>
> Juval Lowy.
>
>
>
>> On both client and server side I have this DataContract and the
>> communication works fine:
>>
>> [DataContract(Name = "Person", Namespace = "ServiceLibrary")]
>> public class Person
>> {
>> [DataMember]
>> public int Id;
>> [DataMember]
>> public string FirstName;
>> [DataMember]
>> public string LastName;
>> }
>> Now I want to change ONLY client to something like this:
>>
>> [DataContract(Namespace = "ServiceLibrary")]
>> public class PersonBase
>> {
>> [DataMember]
>> public string LastName;
>> }
>> [DataContract(Name = "Person", Namespace = "ServiceLibrary")]
>> public class Person : PersonBase
>> {
>> [DataMember]
>> public int Id;
>> [DataMember]
>> public string FirstName;
>> }
>> I tried with various attributes combination to get the thing working
>> but
>> without success.
>> Is there any documentation on the subject?
>> Does anyone has the idea weather something like this is possible?
>> Thanks,
>> Igor.

>
>

My System SpecsSystem Spec
 

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
ACL - Search directories where inheritance has been broken? akcorr PowerShell 2 04-17-2008 08:46 PM
Re: Problem with folder layout inheritance Keith Miller \(MVP\) Vista file management 3 03-15-2008 02:28 AM
WPF Inheritance Russell Mason Avalon 1 07-04-2006 10:25 AM
Abount inheritance and control... Miguel Ortiz Falcón Avalon 1 05-08-2006 08:47 AM
How can I alter the dependency property inheritance chain? Pascal Bourque Avalon 4 05-01-2006 10:08 AM


Update your Vista Drivers Update Your Drivers Now!!

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