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

Nesting DataContracts...

 
 
Thread Tools Display Modes
Old 10-25-2007   #1 (permalink)
Siva
Guest


 

Nesting DataContracts...

Hi,
In my WCF service I have a need to nest Datacontracts.
I need to serialize a struct which contains a class as one of its members.
Here is the format:

public struct struct1
{
public string member1;
public string member2;
public string member3;

public class1 class11; //class1 is a class which contains a bunch of
members

}
I decorated the struct with DataContract attribute and decorated all its
members with DataMember attribute w. How do I go about serializing the
members of class1?
I tried to decorate it with DataMember attribute but I got an exception
while I tried to create a proxy . I also got a hint to mark it with
DataContract attribute and then mark its members with DataMember attribute. I
tired that but I got a compilation error saying that DataContract attribute
is valid only inside class,struct,enum etc. How do I got about accomplishing
what I need?
Thanks
-Siva R
Old 10-26-2007   #2 (permalink)
Vadym Stetsiak
Guest


 

Re: Nesting DataContracts...

Hello, Siva!

Is this what you need?

[DataContract]
public class Struct1
{
[DataMember]
public string memeber1;

[DataMember]
public Struct2 member2;
}

[DataContract]
public class Struct2
{
[DataMember]
public string anothermemeber;
}
--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com

You wrote on Thu, 25 Oct 2007 14:33:00 -0700:

S> Hi,
S> In my WCF service I have a need to nest Datacontracts.
S> I need to serialize a struct which contains a class as one of its
S> members.
S> Here is the format:

S> public struct struct1 {
S> public string member1;
S> public string member2;
S> public string member3;

S> public class1 class11; //class1 is a class which contains a bunch
S> of members

S> }
S> I decorated the struct with DataContract attribute and decorated all
S> its members with DataMember attribute w. How do I go about
S> serializing the members of class1?
S> I tried to decorate it with DataMember attribute but I got an
S> exception while I tried to create a proxy . I also got a hint to
S> mark it with
S> DataContract attribute and then mark its members with DataMember
S> attribute. I tired that but I got a compilation error saying that
S> DataContract attribute is valid only inside class,struct,enum etc.
S> How do I got about accomplishing what I need?
S> Thanks -Siva R



 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem nesting controls Winthrop Chan Avalon 0 03-11-2006 02:42 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