Applying XmlArrayAttribute to the return value that returns an array of complex objects???

B

Bob Rock

Hello,

I read that XmlArrayAttribute may be applyed to "the return value that
returns an array of complex objects" but I don't understand how.
I'd like it to apply it to a method returning an array of objects of a
custom class. How can this be achieved???


Bob Rock
 
D

Dino Chiesa [Microsoft]

Use [return:XmlArray] and [return:XmlArrayItem] on the return type to get it
to behave the way you want.

[WebMethod(Description="Returns an ArrayList, using XmlArrayItem to type
the members. This works. ")]
[return:System.Xml.Serialization.XmlArray(ElementName="MyCollection",
Namespace="http://something.org/2003/10/types")]
[return: System.Xml.Serialization.XmlArrayItem(ElementName="Emp",
Type=typeof(CEmployee))]
[return: System.Xml.Serialization.XmlArrayItem(ElementName="Mgr",
Type=typeof(CDeptManager))]
[return: System.Xml.Serialization.XmlArrayItem(ElementName="Exec",
Type=typeof(CExecutive))]
[return:
System.Xml.Serialization.XmlRoot("TypedList",
Namespace="http://something.org/2003/10/types")
]
public System.Collections.ArrayList GetList_ArrayList_TypedArray()
{
.....
return whatever;
}



But, I think if you include an item in the ArrayList that is not included in
the list of [return:XmlArrayItem(...)] attributes, you'll get a runtime
error. To avoid this, you need to include a typeof(Object), which is like a
catch-all.

-Dino
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top