HighTechTalks DotNet Forums  

Indexer Properties And WebServices

ASP.net Web Services microsoft.public.dotnet.framework.aspnet.webservices


Discuss Indexer Properties And WebServices in the ASP.net Web Services forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Ram
 
Posts: n/a

Default Indexer Properties And WebServices - 03-05-2006 , 06:39 AM






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
  #2  
Old   
Josh Twist
 
Posts: n/a

Default Re: Indexer Properties And WebServices - 03-05-2006 , 02:28 PM






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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="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
  #3  
Old   
Josh Twist
 
Posts: n/a

Default Re: Indexer Properties And WebServices - 03-06-2006 , 02:15 AM



Correction - I actually think it's IList the serializer looks for, not
ICollection.

Josh
http://www.thejoyofcode.com/


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.