Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Indexer Properties And WebServices

Reply
Thread Tools

Indexer Properties And WebServices

 
 
Ram
Guest
Posts: n/a
 
      03-05-2006
Hey,
I have a class with an indexer property, e.g:
public MyClass
{
private ArrayList _list=new ArrayList();

public AnotherType this[int Index]
{
get
{
return (AnotherType)_list[Index];
}
}
}

In my WebService I have a WebMethod returning a MyClass object.
No matter what I tried, the SOAP returned by this WebMethod always
returns an empty _list!
Is there a way to force the XML Serializer to serialize the _list
object?
Thanks ahead

--sternr

 
Reply With Quote
 
 
 
 
Josh Twist
Guest
Posts: n/a
 
      03-05-2006
The XmlSerializer can't serialize your classes indexer because it
doesn't know it's a collection (it doesn't implement ICollection). You
could probably implement ICollection (particularly easy in .NET 2.0
thanks to Generics, but I assume you're using .NET 1.x because you're
using ArrayList) but the easiest thing to do is change your class
slightly like so...

public class MyClass
{
private ArrayList _list = new ArrayList();

[XmlArray("MyList"), XmlArrayItem("Item", typeof(AnotherType))]
public ArrayList Items
{
get
{
return _list;
}
}
}

Which serializes to:

<MyClass xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xmlnssd="http://www.w3.org/2001/XMLSchema">
<MyList>
<Item>test1</Item>
<Item>test2</Item>
</MyList>
</MyClass>

If you're using .NET 2.0, give me a shout and I;ll send the generics
based example. Hope that helps.

Josh
http://www.thejoyofcode.com/

 
Reply With Quote
 
 
 
 
Josh Twist
Guest
Posts: n/a
 
      03-06-2006
Correction - I actually think it's IList the serializer looks for, not
ICollection.

Josh
http://www.thejoyofcode.com/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ObjectDataSource - possible to bind to indexer or indexed property? KJ ASP .Net 1 03-29-2007 12:02 PM
site indexer and search script flupke Python 0 02-17-2005 04:32 PM
Command Window "object doesn't have an indexer" error message joeycalisay ASP .Net 0 12-09-2004 07:09 AM
Which indexer to use? Chris ASP .Net 2 04-19-2004 12:09 PM
code indexer Kevin Collins Perl 1 10-02-2003 04:35 PM



Advertisments