[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webservices

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

Bob Rock

6/4/2004 5:00:00 PM

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


1 Answer

Dino Chiesa [Microsoft]

6/8/2004 2:59:00 AM

0

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/t...)]
[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/t...)
]
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



"Bob Rock" <nospam.yet_another_apprentice@hotmail.com> wrote in message
news:emHMoSkSEHA.2612@TK2MSFTNGP10.phx.gbl...
> 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
>
>