AlGu

Hi, could i create a datacontract wich has a datamenber that reference this datacontract I need it to rapresent a tree.

Example:

[DataControct]

class A

{

[DataMember]

public A[] child;

}

Actualy i have a runtime error.

Tanks.



Re: Windows Communication Foundation (Indigo) DataContract self reference

Dwight Goins

the code below works just fine:

Try making your Class A Public...

Code Snippet

[DataContract]
public class DataContract1
{
string firstName;
string lastName;

private DataContract1[] test;

[DataMember]
public DataContract1[] Tests
{
get { return test; }
set { test = value; }
}

[DataMember]
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
[DataMember]
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
}

Check out a link here when using Arrays and collections types with DataContracts in WCF:

http://msdn2.microsoft.com/en-us/library/aa347850.aspx

HTH






Re: Windows Communication Foundation (Indigo) DataContract self reference

AlGu

Your data contract works fine... but my (as in sample) doesn't work:

[DataContract]

public class MyTreeItem

{

public string name;

[DataMember]

public MyTreeItem[] childs;

[DataMember]

public MyTreeItem parent;

}

[OperationContract]

public MyTreeItem[] Test()

{

//it woks fine

return new MyTreeItem[10];

//it woks fine

MyTreeItem[] res = new MyTreeItem[10];

for(int i=0; i<res.Length; i++)

{

res[ i ] = new MyTreeItem();

res[ i ].name = "abc";

res[ i ].childs = new MyTreeItem[15];

}

return res;

//it works fine

MyTreeItem[] res = new MyTreeItem[10];

for(int i=0; i<res.Length; i++)

{

res[ i ] = new MyTreeItem();

res[ i ].parent = new MyTreeItem();

res[ i ].name = "abc";

res[ i ].childs = new MyTreeItem[15];

}

return res;

//it doesn't work

MyTreeItem[] res = new MyTreeItem[2];

for (int i = 0; i < res.Length; i++)

{

res[ i ] = new MyTreeItem();

res[ i ].parent = new MyTreeItem();

res[ i ].name = "abc";

res[ i ].childs = new MyTreeItem[3];

for (int j = 0; j < res[ i ].childs.Length; j++)

{

res[ i ].childs[j] = new MyTreeItem();

res[ i ].childs[j].name = "abcdef";

res[ i ].childs[j].parent = res[ i ];

res[ i ].childs[j].childs = new MyTreeItem[4];

}

}

return res;

}

in this case i use the same object more then on time.

Message error:

An error occurred while receiving the HTTP response to http://localhost:8000/MyService/wsHttpBinding. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

Why





Re: Windows Communication Foundation (Indigo) DataContract self reference