S
Sinex
Hi ,
I have some problem in XML Serialization. Basically.the trouble is when I am
trying to serialize nested ArrayList (or arrays). The serializer is not able
to determine the type of elementes stored in the nested (inner) ArrayList.
Heres some sample code with the SOAP envelope that is generated and I have
mentioned the SOAP envelope that is required at the end. See if you can make
out nething that I am missing..
class part
{
public int f1;
public int f2;
}
class machine
{
[XmlArray(ElementName="parts")]
[XmlArrayItem(ElementName="part", Type=typeof(part))]
public ArrayList manyParts;
}
class webservice
{
[return: XmlElement(typeof(machines[]))]
public ArrayList mywebmethod()
{
part p1 = new part(); p1.f1 = 10; p1.f2 = 20;
part p2 = new part(); p2.f1 = 30; p2.f2 = 40;
part p3 = new part(); p1.f1 = 10; p1.f2 = 20;
part p4 = new part(); p2.f1 = 30; p2.f2 = 40;
machine m1 = new machine();
m1.manyParts = new ArrayList(2);
m1.Add(p1); m1.Add(p2);
machine m2 = new machine();
m2.manyParts = new ArrayList(2);
m2.Add(p3); m1.Add(p4);
ArrayList manyMachines = new ArrayList(2);
manyMachines.Add(m1); manyMachines.Add(m2);
return manyMachines;
}
}
Serialized SOAP being generated:
<machines>
<machine>
<parts>
<part xsi:nil="true" />
<part xsi:nil="true" />
<parts>
</machine>
</machines>
Required SOAP format:
<machines>
<machine>
<parts>
<part>
<f1>10</f1>
<f2>20</f2>
</part>
<part>
<f1>30</f1>
<f2>40</f2>
</part>
<parts>
</machine>
</machines>
I have some problem in XML Serialization. Basically.the trouble is when I am
trying to serialize nested ArrayList (or arrays). The serializer is not able
to determine the type of elementes stored in the nested (inner) ArrayList.
Heres some sample code with the SOAP envelope that is generated and I have
mentioned the SOAP envelope that is required at the end. See if you can make
out nething that I am missing..
class part
{
public int f1;
public int f2;
}
class machine
{
[XmlArray(ElementName="parts")]
[XmlArrayItem(ElementName="part", Type=typeof(part))]
public ArrayList manyParts;
}
class webservice
{
[return: XmlElement(typeof(machines[]))]
public ArrayList mywebmethod()
{
part p1 = new part(); p1.f1 = 10; p1.f2 = 20;
part p2 = new part(); p2.f1 = 30; p2.f2 = 40;
part p3 = new part(); p1.f1 = 10; p1.f2 = 20;
part p4 = new part(); p2.f1 = 30; p2.f2 = 40;
machine m1 = new machine();
m1.manyParts = new ArrayList(2);
m1.Add(p1); m1.Add(p2);
machine m2 = new machine();
m2.manyParts = new ArrayList(2);
m2.Add(p3); m1.Add(p4);
ArrayList manyMachines = new ArrayList(2);
manyMachines.Add(m1); manyMachines.Add(m2);
return manyMachines;
}
}
Serialized SOAP being generated:
<machines>
<machine>
<parts>
<part xsi:nil="true" />
<part xsi:nil="true" />
<parts>
</machine>
</machines>
Required SOAP format:
<machines>
<machine>
<parts>
<part>
<f1>10</f1>
<f2>20</f2>
</part>
<part>
<f1>30</f1>
<f2>40</f2>
</part>
<parts>
</machine>
</machines>