Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
Returning a ICollection based class (again)
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.aspnet.webservices.


FredCK
Hello,

Let's try again:

I implemented the ICollection inteface in "MyClassList" and it works
well. Using it in a Windows Form project, I could easily do a "foreach
(MyClass in MyClassList)" to list all "MyClass"'s.

But then I created a WebService with the following method:

[WebMethod]
public MyClassList GetMyClassList()
{
MyClassList oMyClassList = new MyClassList () ;
return oMyClassList ;
}

When I pressed "F5" to run it, the compilation ran OK but in IE the
following message appeared:

System.InvalidOperationException: You must implement a default accessor on
MyNamespace.MyClassList because it inherits from ICollection

Does anyone now what to do? How can I return my ICollection based class?

Thanks in advance,
Fred

Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
Bob Beauchemin
Hi Fred,

I've been able to return a class that derives from CollectionBase. In fact,
I just used the typed Collection generator on gotdotnet.com to generate a
simple collection of this type of sent it as a return parm from a WebService
without problems. As a test, I'd try one of these collections (generator by
the typed Collection generator), then compare it to your collection class.
Also, you can attempt to serialize your class with the XmlSerializer to see
if that works.

Hope this helps,
Bob Beauchemin
Click here to reveal e-mail address

"FredCK" <Click here to reveal e-mail address> wrote in message
news:OkwK8hXfBHA.1996@tkmsftngp03...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
FredCK
Thanks a lot Bob,

Your tip made me able to understand what the "default accessor" is. It
is the special property that returns an object of the collection based on
its index. But not only this... for a Web Service it defines what is the
BaseClass of my Collection.

This is the example of the implementation:

[Serializable()]
public class MyClassList : System.Collections.ICollection
{
private System.Collections.ArrayList colMyClass = new
System.Collections.ArrayList() ;

// Default Accessor Implementation
public MyClass this[int index]
{
get
{
if (! bIsLoaded) { Reload() ; }
return ((MyClass)(colMyClass [index]));
}
set { /* Do Nothing */ }
}

Thanks again,
Fred

"Bob Beauchemin" <Click here to reveal e-mail address> wrote in message
news:etsgwaqfBHA.1564@tkmsftngp02...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
 
 
System.Collections.ArrayList
System.Collections.CollectionBase
System.Collections.ICollection
System.InvalidOperationException
System.Web.Services.WebService
System.Xml.Serialization.XmlSerializer




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734